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
  • Basic
  • Passing options to nestings
  • Passing nesting to interpolated
  • Additional options
  1. Translation Function

Nesting

Nesting allows you to reference other keys in a translation. Could be useful to build glossary terms.

Basic

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)",

Passing options to nestings

You can pass entire data models in options.

keys

{
    "girlsAndBoys": "They have $t(girls, {\"count\": {{girls}} }) and $t(boys, {\"count\": {{boys}} })",
    "boys": "{{count}} boy",
    "boys_other": "{{count}} boys",
    "girls": "{{count}} girl",
    "girls_other": "{{count}} girls",
}

sample

i18next.t('girlsAndBoys', {girls: 3, boys: 2});
// -> "They have 3 girls and 2 boys"

Make sure the options string is valid JSON and can be parsed using JSON.parse

'sampleKey': 'test $t(nest2, { "changedVarName": "{{var}}" })'

Passing nesting to interpolated

keys

{
      "key1": "hello world",
      "key2": "say: {{val}}"
}

sample

i18next.t('key2', {val: '$t(key1)'});
// -> "say: hello world"
interpolation: {
  skipOnVariables: false
}

Additional options

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.

Last updated 1 year ago

If you're using >= v21.0.0 you need to set to false:

Prefix/Suffix for nesting and other options can be overridden in init or by passing additional options to t function:

skipOnVariables
interpolation options