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

Issue with getting value from i18n.__("Hello") #119

Open
nijat13 opened this issue Apr 15, 2018 · 3 comments
Open

Issue with getting value from i18n.__("Hello") #119

nijat13 opened this issue Apr 15, 2018 · 3 comments

Comments

@nijat13
Copy link

nijat13 commented Apr 15, 2018

Hello!
I've tried to use this lib in my own project. But basic configuration doesn't work for me.
Here's the language files:
locales/en.json

{
    "Hello": "Hello EN",
    ....
}

locales/de.json

{
    "Hello": "Hello DE",
    ....
}

Here's the express.js:


var i18n = new (require('i18n-2'))({
    // setup some locales - other locales default to the first locale
    locales: ['en', 'de'],
    extension: '.json',
    directory: path.join(__dirname, '/locales')
});

// Use it however you wish
console.log( 'i18n-2 Hello value: ', i18n.__("Hello") );

This console gives thee Hello instead of Hello EN.

Additionally, my i18n object looks like this:

{ devMode: true,
locales: { en: {}, de: {} },
extension: '.json',
directory: '/backend-app/dist/config/locales',
defaultLocale: 'en',
locale: 'en' }

Thanks in advance!

@iKonrad
Copy link

iKonrad commented Aug 10, 2018

@nijat13 I've got exactly same issue. Have you managed to find out what the issue was?

@iKonrad
Copy link

iKonrad commented Aug 10, 2018

Okay, in my case it was the missing defaultLocale setting.

But in your case (I can see that you've submitted this a few months ago but maybe someone will have a similar issue), I think you need to add a parse function that will transform your json into a JS object.

Mine looks like this:

      parse(data) {
        const parsed = JSON.parse(data.toString());
        return parsed;
      },

@rmartinez-alfredsmart
Copy link

Hi, I do have the same problem, any solution?

Thanks.

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

3 participants