Browse Source

Keep en lang always imported

pull/2385/head
Artur Arseniev 6 years ago
parent
commit
965fdafc62
  1. 4
      docs/modules/I18n.md
  2. 13
      src/i18n/index.js
  3. 7
      test/specs/i18n/index.js

4
docs/modules/I18n.md

@ -23,8 +23,8 @@ By default, the editor includes only the English language, if you need other lan
```js
import grapesjs from 'grapesjs';
import en from 'grapesjs/locale/en';
import it from 'grapesjs/locale/it';
import tr from 'grapesjs/locale/tr';
const editor = grapesjs.init({
...
@ -32,7 +32,7 @@ const editor = grapesjs.init({
// locale: 'en', // default locale
// detectLocale: true, // by default, the editor will detect the language
// localeFallback: 'en', // default fallback
messages: { en, it },
messages: { it, tr },
}
});
```

13
src/i18n/index.js

@ -6,9 +6,7 @@
* locale: 'en',
* localeFallback: 'en',
* messages: {
* en: {
* hello: 'Hello',
* },
* it: { hello: 'Ciao', ... },
* ...
* }
* }
@ -66,7 +64,14 @@ export default () => {
* @private
*/
init(opts = {}) {
this.config = { ...config, ...opts };
this.config = {
...config,
...opts,
messages: {
...config.messages,
...(opts.messages || {})
}
};
if (this.config.detectLocale) {
this.config.locale = this._localLang();

7
test/specs/i18n/index.js

@ -42,6 +42,13 @@ describe('I18n', () => {
expect(obj.getLocale()).toBe(locale);
});
test('English always imported', () => {
obj.init({
messages: { it: {} }
});
expect(Object.keys(obj.getMessages())).toEqual(['en', 'it']);
});
test('setLocale and getLocale methods', () => {
const localeBefore = obj.getLocale();
const localeNew = `${localeBefore}2`;

Loading…
Cancel
Save