Querystring param:
The current locale to set will be looked up in the new parameter: ?lang=en-US
. Default is ?setLng=en-US
.
i18n.init({
detectLngQS: 'lang'
});
Cookie name:
The current locale to set and looked up in the given cookie parameter.
i18n.init({
cookieName: 'lang' // default 'i18next'
});
Cookie domain:
Sets the cookie domain to given value.
i18n.init({
cookieDomain: '*.mydomain.com'
});
Cookie usage:
Use this only if your sure that language will be provided by the other lookup options or set programatically.
i18n.init({
useCookie: false
});
Preload additional languages on init:
The additional languages will be preloaded on init
.
i18n.init({
preload: ['de-DE', 'fr']
});
Preload additional languages after init:
The additional languages will be preloaded after init
by calling this function.
i18n.preload([lngs], callback)
Languages whitelist:
Only specified languages will be allowed to load.
i18n.init({
lngWhitelist: ['de-DE', 'de', 'fr']
});
Additional namespaces:
The additional namespaces will be loaded.
// Single
i18n.loadNamespace('myNamespace', function() {
// loaded
});
// or multiple
i18n.loadNamespaces([
'myNamespace1',
'myNamespace2'
], function() {
// loaded
});
Unset/Set fallback language:
If not set it will default to 'dev'
. If turned on, all missing key/values will be sent to this language.
// Single
i18n.init({
fallbackLng: 'en'
});
// or multiple
i18n.init({
fallbackLng: ['fr', 'en']
});
Turn off fallback:
As the fallbackLng will default to 'dev'
you can turn it off by setting the option value to false
. This will prevent loading the fallbacks resource file and any futher look up of missing value inside a fallback file.
i18n.init({
fallbackLng: false
});
Load locales:
If load option is set to current
i18next will load the current set language (this could be a specific (en-US) or unspecific (en) resource file).
i18n.init({
load: 'current'
});
If set to unspecific i18next will always load the unspecific resource file (eg. en instead of en-US).
i18n.init({
load: 'unspecific'
});
Caching with localStorage:
Caching is turned off by default. If the resouces in a given language had been stored to localStorage
they won't be fetched / reloaded from online until set localStorageExpirationTime
expired. So if they had been cached once and you add new resources, they won't be reloaded until expired. But you can easily remove the values from localstorage by calling, eg.: localStorage.removeItem("res_en" )
.
i18n.init({
useLocalStorage: true | false,
localStorageExpirationTime: 86400000 // in ms, default 1 week
});
Null values:
Default is true
.
i18n.init({
fallbackOnNull: true | false
});
Empty string values:
Default is false
.
i18n.init({
fallbackOnEmpty: true | false
});
Debug output:
If something went wrong you might find some helpful information on console log.
i18n.init({
debug: true
});