React-i18next: Access nested object

Created on 24 May 2019  路  2Comments  路  Source: i18next/react-i18next

Access nested object

Hello guys :)

so we have nested object

  en: {
      translations: {
        "hello": "hello_EN",
        "nested": { "test": "testEN" },
        "one": {"two": {"three": "superNested_EN"}}
      }
    },

// this works fine
{this.props.t('hello')}

// and this is not works

{this.props.t('nested.test')} 
{this.props.t('one.two.three')}

untill in our i18n init object we will not add keySeparator: "."
by default it's keySeparator: false

I spent some time to find out how to access nested objects and I haven't found nothing about it in documentation. Or I missed something ? :(

Most helpful comment

Thanks for ur answer. Seems I missed something. Because when I created settings for my react app I made keySeparator: false and after I spent half day to undestand why nesting isn't works :(

All 2 comments

the default is . https://github.com/i18next/i18next/blob/master/src/defaults.js#L17

the sample might use keySeparator: false but the default if omitting that on init is .

Thanks for ur answer. Seems I missed something. Because when I created settings for my react app I made keySeparator: false and after I spent half day to undestand why nesting isn't works :(

Was this page helpful?
0 / 5 - 0 ratings