Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how does deep key works? #358

Closed
Grsmto opened this issue Dec 7, 2017 · 8 comments
Closed

Question: how does deep key works? #358

Grsmto opened this issue Dec 7, 2017 · 8 comments

Comments

@Grsmto
Copy link

Grsmto commented Dec 7, 2017

Hi,

I'm trying to access a translation from a deep object but I feel like I'm missing a point. Best is to check the Webpack Bin there.

en: {
        translations: {
          "actions": {
            "click": "click here"
          }
        }
}

<h2>{t('actions.click')}</h2> // will output "actions.click"!??? :/

Thanks for your help!

@jamuhl
Copy link
Member

jamuhl commented Dec 7, 2017

see i18n.js line 35 -> we turned keySeparation "off" - so keys can't be nested

having key "actions.click": "click here" would work but no actions: { click: "click here" } 

https://www.i18next.com/principles/fallback.html#key-fallback

@Grsmto
Copy link
Author

Grsmto commented Dec 7, 2017

🙏 thank you very much.

@Grsmto Grsmto closed this as completed Dec 7, 2017
@jamuhl
Copy link
Member

jamuhl commented Dec 7, 2017

you're welcome

@sudthenerd
Copy link

Sorry but it's Not working.
I created different file for each namespace.
And have nested keys.
locale/en/customer.json
{
"title": {"key": "translation"}
}

locale/fr/customer.json
{
"title": {"key": "fr translation"}
}

as you can see, I have two file for namespace customer. and I want deep key support like
t('title.key')
But it's not working.

Thanks 😊

@sudthenerd
Copy link

I was using addResource to add resources dynamically.
and now I. Using
i18n.addResourceBundle(language, namespace, resourcesForLanguage, true)

n it's working fine.

Thanks community😊🤸🕺
Happy coding😊

@zevero
Copy link

zevero commented Jan 21, 2020

Didn't get it from the above comments.
To use deep keys seperated by '.' just set
keySeparator: '.'
when set to false it wont look for deep keys (as for true)

@jamuhl
Copy link
Member

jamuhl commented Jan 21, 2020

@zevero yes default is . so not overriding it to false will do it -> not like to use it - set to false, like different char - set that

@flancer64
Copy link

Thanks, @sudthenerd !

Deep keys don't work with i18next.addResources, we need to use i18next.addResourceBundle.

Wrong way:

i18next.addResources('en', 'mySpace', {
    look: {
        deep: 'value of look deep'
    }
});
i18next.t('mySpace:look.deep'); // 'look.deep' - failed!

Right way:

i18next.addResourceBundle('en', 'mySpace', {
    look: {
        deep: 'value of look deep'
    }
}, true);
i18next.t('mySpace:look.deep'); // 'value of look deep' - succeed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants