From 965fdafc62e3de4a36fd172edb22d68612a40ecd Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Mon, 4 Nov 2019 22:06:56 +0100 Subject: [PATCH] Keep en lang always imported --- docs/modules/I18n.md | 4 ++-- src/i18n/index.js | 13 +++++++++---- test/specs/i18n/index.js | 7 +++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/modules/I18n.md b/docs/modules/I18n.md index 63c4e63ea..0c6f047e8 100644 --- a/docs/modules/I18n.md +++ b/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 }, } }); ``` diff --git a/src/i18n/index.js b/src/i18n/index.js index 91179d3ba..0225ea424 100644 --- a/src/i18n/index.js +++ b/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(); diff --git a/test/specs/i18n/index.js b/test/specs/i18n/index.js index 4fba52d15..87e3e3816 100644 --- a/test/specs/i18n/index.js +++ b/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`;