Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.

How can i change default lang in app? #61

Open
dinfyru opened this issue Aug 28, 2017 · 1 comment
Open

How can i change default lang in app? #61

dinfyru opened this issue Aug 28, 2017 · 1 comment

Comments

@dinfyru
Copy link

dinfyru commented Aug 28, 2017

How can i change default lang in app (setLocale or other)?
webpack.config.js

const i18nEN = require('./src/config/lang/en.json');
const i18nRU = require('./src/config/lang/ru.json');

const languages = {
  en: i18nEN,
  ru: i18nRU
};

module.exports = {
...
plugins: [
    new I18nPlugin(languages.en),
    new I18nPlugin(languages.ru)
]
};

app.js
__('login_form.emailField')

en.js

{
  "login_form.emailField": "Email",
}

ru.js

{
  "login_form.emailField": "Имэйл",
}
@sullenor
Copy link
Collaborator

sullenor commented Aug 28, 2017

You should load necessary javascript bundle for the chosen language.
The simple way is to make a html page for each locale and redirect to the necessary one via link.

You should create a configuration for each language, for example:

module.exports = [
  {
    ...
    plugins: [
      new I18nPlugin(languages.en)
    ],
    output: {
      ...
      filename: 'en.js'
    }
  },
  {
    ...
    plugins: [
      new I18nPlugin(languages.ru)
    ],
    output: {
      ...
      filename: 'ru.js'
    }
  }
];

It will produce a javascript bundles with corresponding translations (two for your example). And you'll have to load the necessary one depending on the chosen language.

There is a small example here: https://github.com/webpack/webpack/blob/master/examples/i18n/webpack.config.js

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

No branches or pull requests

2 participants