Nesting allows you to reference other keys in a translation. Could be useful to build glossary terms.
keys
{
"nesting1": "1 $t(nesting2)",
"nesting2": "2 $t(nesting3)",
"nesting3": "3",
}
sample
i18next.t('nesting1'); // -> "1 2 3"
You can reference keys from other namespaces by prepending the namespace: "nesting1": "1 $t(common:nesting2)",
You can pass entire data models in options.
keys
{
"girlsAndBoys": "$t(girls, {'count': {{girls}} }) and {{count}} boy",
"girlsAndBoys_plural": "$t(girls, {'count': {{girls}} }) and {{count}} boys",
"girls": "{{count}} girl",
"girls_plural": "{{count}} girls"
}
sample
i18next.t('girlsAndBoys', {count: 2, girls: 3});
// -> "3 girls and 2 boys"
keys
{
"key1": "hello world",
"key2": "say: {{val}}"
}
sample
i18next.t('key2', {val: '$t(key1)'});
// -> "say: hello world"
Prefix/Suffix for nesting and other options can be overridden in init interpolation options or by passing additional options to t function:
sample
i18next.init({
interpolation: { ... }
});
i18next.t('key', {
interpolation: { ... }
});
option | default | description |
---|---|---|
nestingPrefixEscaped | undefined | escaped prefix for nesting (regexSafe) |
nestingSuffixEscaped | undefined | escaped suffix for nesting (regexSafe) |
While there are a lot of options going with the defaults should get you covered.