jeresig / i18n-node-2

Lightweight simple translation module for node.js / express.js with dynamic json storage. Uses common __('...') syntax in app and templates.
MIT License
507 stars 79 forks source link

What is the proper way to call i18n-2 accross main.js and renderer.js #112

Open matejmosko opened 6 years ago

matejmosko commented 6 years ago

Hello, I am struggling with the way how to properly call i18n accross whole my electron app.

Now I have this setup

main.js

const i18n = new (require('i18n-2'))({
    locales: ['en', 'sk']
});
global.i18n = i18n;
i18n.setLocaleFromEnvironmentVariable();

renderer.js

const i18n = remote.getGlobal('i18n');

Translations work as intended, even the Locale is shared. However I get strings from renderer.js detected and written in sk.js (enviroment variable) instead of en.js. Is it intended?

Thanks.

gjuchault commented 6 years ago

I'm not sure how i18n would be the cause of the locale change. Can you check what environment variables you have in main/renderer ? Maybe that comes from here.

You can also enforce language from renderer based on the language in main (something like i18n.setLocale(remote.getGlobale('locale')) (Maybe that would work).

If nothing of this helps you, can you make an example repository that I can clone ?