Core: Cannot access the nested JSON Object

Created on 14 Jan 2016  路  5Comments  路  Source: ngx-translate/core

I am facing an issue, when i am using single string value in JSON it works, but when using object instead it doesn't works, below is the code explained.

   translate.setDefaultLang('en');

    translate.setTranslation('en', {
        "helloWorld": {
             "sayHello": "Hello there!"
         },
         "helloWorldSayHello": "Hello there!"
    });

    this.translate.use('en');
    <div>{{ 'helloWorldSayHello' | translate }} world</div> ----------//this does work
    <div>{{ 'helloWorld.sayHello' | translate }} world</div> ----------//this doesn't work

Is their any other way to make it work?

feature request

Most helpful comment

Not yet, but it's just a matter of improving the parser, I'll put it on my todo list :)

All 5 comments

Not yet, but it's just a matter of improving the parser, I'll put it on my todo list :)

:+1: I'm currently looking to rebuild an existing app in Ionic2/Angular2 - our translations are created using https://webtranslateit.com/en and the resulting json looks like this: https://github.com/openchargemap/ocm-system/blob/master/Localisation/src/OCM_UI_LocalisationResources.it.json

When the translation for the selected language is null, we fallback (currently to the default text in the app). It would also be great to specify a fallback language in config. So if your app is in English but is mostly translated to Japanese then you could fallback to English.

Thank you @ocombe ! you are doing a great job :+1:

Both features are available in 1.4.0 !

Still having issues with attempting to use a nested json source for translations.
<div>{{ 'helloWorld.sayHello' | translate }}</div>
displays [Object object] rather then the translation value

Was this page helpful?
0 / 5 - 0 ratings