Configuration Options
i18next.init(options, callback)
All options for calling init()
or createInstance()
.
Logging
option | default | description |
---|---|---|
debug | false | logs info level to console output. Helps finding issues with loading not working. |
Languages, namespaces, resources
option | default | description |
---|---|---|
resources | undefined | resources to initialize with (if not using a backend plugin or not using |
lng | undefined | language to use (overrides language detection). If set to |
appendNamespaceToCIMode | false | prefixes the namespace to the returned key when using |
fallbackLng | 'dev' | language to use if translations in user language are not available. Setting it explicitly to |
supportedLngs | false | array of allowed languages |
nonExplicitSupportedLngs | false | if true, will consider variants as supported when the main language is. E.g. If true and using a backend like i18next-http-backend, this can cause some request errors. |
load | 'all' | strategy to define which language codes to lookup. Example: given set language is |
preload | false | array of languages to preload. Important on server-side to assert translations are loaded before rendering views. |
lowerCaseLng | false | locale will be fully lowercased; e.g. |
cleanCode | false | main language will be lowercased; e.g. |
ns | 'translation'
(setting it to an empty array | string or array of namespaces to load |
defaultNS | 'translation' (if a | default namespace used if not passed to the translation function |
fallbackNS | false | string or array of namespaces to lookup key if not found in given namespace. See NS fallback docs. |
partialBundledLanguages | false | allows some resources to be set on initialization while others can be loaded using a backend connector |
Missing keys
The missing keys functionality of i18next is very useful during development. If enabled (saveMissing: true
), it collects the used i18n keys that are not yet part of your translation resources and tries to save them to the used backend (a backend plugin that offers the create function is necessary for this).
In this video you can see how the saveMissing functionality is used.
option | default | description |
---|---|---|
saveMissing | false | calls save missing key function on backend if key not found (only for backends that supports the create function, i.e. i18next-fs-backend, i18next-http-backend, i18next-locize-backend etc.) |
updateMissing | false | experimental: enable to update default values using the |
saveMissingTo | 'fallback' |
|
saveMissingPlurals | true | will save all plural forms instead of only singular if t was called for plurals |
missingKeyHandler | false |
The |
parseMissingKeyHandler | noop |
|
appendNamespaceToMissingKey | false | appends namespace to missing key |
missingInterpolationHandler | noop |
|
missingKeyNoValueFallbackToKey | false | Used to not fallback to the key as default value, when using saveMissing functionality. * i.e. when using with i18next-http-backend this will result in having a key with an empty string value. |
Translation defaults
option | default | description |
---|---|---|
postProcess | false | string or array of postProcessors to apply per default |
returnNull | false | allows null values as valid translation |
returnEmptyString | true | allows empty string as valid translation |
returnObjects | false | allows objects as valid translation result |
returnDetails | false | returns an object that includes information about the used language, namespace, key and value |
returnedObjectHandler | noop |
|
joinArrays | false | char that arrays will be joined by; e.g. ", " |
overloadTranslationOptionHandler | function(args) { return { defaultValue: args[1] }; }; | default: sets defaultValue |
interpolation | see interpolation | |
skipInterpolation | false | Allow translate function to skip interpolation and return raw values instead |
(used in format < format v4) |
|
|
Plugin options
option | default | description |
---|---|---|
detection | undefined | options for language detection - check docs |
backend | undefined | options for backend - check docs |
cache | undefined | options for a cache layer in backends - check docs |
Others
option | default | description |
---|---|---|
initAsync | true | triggers resource loading in |
keySeparator |
| char to separate keys. If working with a flat JSON, it's recommended to set this to |
nsSeparator |
| char to split namespace from key |
pluralSeparator |
| char to split plural from key |
contextSeparator |
| char to split context from key |
ignoreJSONStructure | true | if a key is not found as nested key, it will try to lookup as flat key |
maxParallelReads | 10 | limits parallel reads to the backend to prevent opening up to thousands of sockets or file descriptors at the same time, leading to |
initImmediate
Sample using initImmediate
when using a backend plugin allowing sync (blocking) loads.
This option only works for sync (blocking) loading backend, like i18next-fs-backend!
Last updated