i18next documentation
🏠 i18next🌐 localization as a service🎓 i18next crash course💾 GitHub Repository
  • Introduction
  • Overview
    • Getting started
    • Comparison to others
    • API
    • Configuration Options
    • Supported Frameworks
    • Plugins and Utils
    • For Enterprises
    • First setup help
    • TypeScript
  • Translation Function
    • Essentials
    • Interpolation
    • Formatting
    • Plurals
    • Nesting
    • Context
    • Objects and Arrays
  • Principles
    • Best Practices
    • Translation Resolution
    • Namespaces
    • Fallback
    • Plugins
  • How to
    • Add or Load Translations
    • Extracting translations
    • Caching
    • Backend Fallback
    • FAQ
  • Misc
    • JSON Format
    • Creating own Plugins
    • Migration Guide
    • The history of i18next
    • Testimonials
  • 🌐localization as a service
  • 🎓i18next crash course
  • 💾GitHub Repository
Powered by GitBook
On this page
  • Logging
  • Languages, namespaces, resources
  • Missing keys
  • Translation defaults
  • Plugin options
  • Others
  • initImmediate
  1. Overview

Configuration Options

Last updated 26 days ago

i18next.init(options, callback)

All options for calling or .

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

lng

undefined

appendNamespaceToCIMode

false

prefixes the namespace to the returned key when using lng: 'cimode'

fallbackLng

'dev'

supportedLngs

false

array of allowed languages

nonExplicitSupportedLngs

false

if true, will consider variants as supported when the main language is. E.g. en-US will be valid if en is in supportedLngs.

load

'all'

strategy to define which language codes to lookup. Example: given set language is en-US: - 'all' ⇒ ['en-US', 'en', 'dev'] - 'currentOnly' ⇒ 'en-US' - 'languageOnly' ⇒ 'en'

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. en-US ⇒ en-us

cleanCode

false

main language will be lowercased; e.g. EN ⇒ en, while leaving full locales like en-US

ns

'translation' (setting it to an empty array [] will not load any namespaces on init)

string or array of namespaces to load

defaultNS

'translation'

fallbackNS

false

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).

option
default
description

saveMissing

false

updateMissing

false

experimental: enable to update default values using the saveMissing (Works only if defaultValue is different from translated value. Only useful on initial development or when keeping code as source of truth not changing values outside of code. Only supported if backend supports it already)

saveMissingTo

'fallback'

saveMissingPlurals

true

will save all plural forms instead of only singular if t was called for plurals

missingKeyHandler

false

function(lngs, ns, key, fallbackValue, updateMissing, options) { } used for custom missing key handling (needs saveMissing set to true!)

parseMissingKeyHandler

noop

appendNamespaceToMissingKey

false

appends namespace to missing key

missingInterpolationHandler

noop

function(text, value) { return 'stringWithAlternativeValueOrUndefined' } gets called in case a interpolation value is undefined. This method will not be called if the value is an empty string or null

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

function(key, value, options) {} gets called if object was passed in as key but returnObjects was set to false

joinArrays

false

char that arrays will be joined by; e.g. ", "

overloadTranslationOptionHandler

function(args) { return { defaultValue: args[1] }; };

default: sets defaultValue

interpolation

skipInterpolation

false

Allow translate function to skip interpolation and return raw values instead

simplifyPluralSuffix

(used in format < format v4)

true

will use 'plural' as suffix for languages only having 1 plural form, setting it to false will suffix all with numbers

Plugin options

option
default
description

detection

undefined

backend

undefined

cache

undefined

Others

option
default
description

initAsync

true

keySeparator

'.'

char to separate keys. If working with a flat JSON, it's recommended to set this to false.

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 EMFILE errors if ulimit -n is exceeded (debug: true must be set to see them). limiting parallelism usually makes loading all items substantially faster than allowing all reads to start before any have finished.

cacheInBuiltFormats

true

initImmediate

Sample using initImmediate when using a backend plugin allowing sync (blocking) loads.

import i18next from 'i18next';
import Backend from 'i18next-fs-backend';

// not working
i18next
  .use(Backend)
  .init();

i18next.t('key'); // -> will not return value as init was run async

/*
execution order of function calls
- init
- t
- loadResources (as called inside timeout)
*/

// working
i18next
  .use(Backend)
  .init({ initImmediate: false });

i18next.t('key'); // -> will return value

/*
execution order of function calls
- init
- loadResources (as called without timeout)
- t
*/

resources to initialize with (if not using a or not using )

language to use (overrides language detection). If set to 'cimode' the output text will be the key.

language to use if translations in user language are not available. Setting it explicitly to false will not trigger to load the fallbackLng at all. .

If true and using a backend like , this can cause some .

(if a ns option and no defaultNS option is defined, the first namespace is used as defaultNS option) (setting it to false or an empty array [] will disable )

default namespace used if not passed to the

string or array of namespaces to lookup key if not found in given namespace. .

you can see how the saveMissing functionality is used.

calls save missing key function on backend if key not found (only for backends that supports the , i.e. , , etc.)

'current' or 'all' By default it uses the configured fallback language to save the missing keys to. 'current' will use the current used/detected language () and 'all' will save it to all languages included in .

The options are an internal value container similar to the . The fallbackValue argument is the value that is shown if the translations are not provided (usually the defaultValue). The updateMissing argument is set to true if the missingKeyHandler function was invoked because of the updateMissing functionality.

function(key, defaultValue, options) { // return value to display } The options are an internal value container similar to the .

see

options for language detection -

options for backend -

options for a cache layer in backends -

triggers resource loading in init() inside a setTimeout (default async behaviour). Set it to false if your backend loads resources synchronously - that way, calling i18next.t() after init() is possible without relying on the initialization callback. This option only works for sync (blocking) loading backend, like !

Initializes the internal formatter for the as cached version. Can be set to false for this type of .

This option only works for sync (blocking) loading backend, like !

init()
createInstance()
In this video
i18next-fs-backend
backend plugin
addResourceBundle
Make sure you use the 'en-US' format, instead of underscores or similar.
See the Fallback docs
i18next-http-backend
request errors
this fallback behaviour
translation function
See NS fallback docs
create function
i18next-fs-backend
i18next-http-backend
i18next-locize-backend
i18next.language
i18next.languages
t() options
t() options
{...}
interpolation
check docs
check docs
check docs
i18next-fs-backend
in-built formats
issues