From e1d6938c15ae81d8dbf69e3987cb8447cac3e441 Mon Sep 17 00:00:00 2001 From: Cristian Necula Date: Fri, 17 Apr 2020 00:50:43 +0300 Subject: [PATCH] feat: allow passing i18next settings to the i18n.t call Fixes https://github.com/Neovici/cosmoz-i18next/issues/53 --- cosmoz-i18next.js | 12 ++++++++++-- test/basic.test.js | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cosmoz-i18next.js b/cosmoz-i18next.js index 89365ac..7b3517b 100644 --- a/cosmoz-i18next.js +++ b/cosmoz-i18next.js @@ -10,7 +10,7 @@ const // even when there is no element in the page. i18n.init({ lng: 'en', - resStore: { en: {}}, + resStore: { en: {} }, fallbackLng: false }); } @@ -26,6 +26,14 @@ const if (object.count === undefined && typeof item === 'number') { object.count = item; } + + if (typeof item === 'object') { + return { + ...object, + ...item + }; + } + object[index] = item; return object; }, {}); @@ -86,7 +94,7 @@ const return i18n.t(key, args); }, loadTranslations = (lang, namespace, translations) => { - i18n.init({ resources: {}}); + i18n.init({ resources: {} }); i18n.addResourceBundle(lang, namespace, translations); }, translatable = dedupingMixin(baseClass => class extends baseClass { diff --git a/test/basic.test.js b/test/basic.test.js index 17d5db1..b9f7b4e 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -64,6 +64,10 @@ suite('core', () => { assert.equal(_('Hello {0}', 'John Doe'), 'Hej John Doe'); assert.equal(_('Hello {0}', 'John Doe'), 'Hej John Doe'); assert.equal(_('Hello {0}', 'John Doe'), gettext('Hello {0}', 'John Doe')); + assert.equal( + _('Hello {0}', 'John Doe', { interpolation: { escapeValue: false }}), + 'Hej John Doe' + ); }); test('ngettext / plural', () => {