Skip to content

Commit

Permalink
feat: allow passing i18next settings to the i18n.t call
Browse files Browse the repository at this point in the history
Fixes #53
  • Loading branch information
cristinecula authored and nomego committed Apr 16, 2020
1 parent 1671d97 commit e1d6938
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cosmoz-i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const
// even when there is no <i18next> element in the page.
i18n.init({
lng: 'en',
resStore: { en: {}},
resStore: { en: {} },
fallbackLng: false
});
}
Expand All @@ -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;
}, {});
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}', '<a href="mailto:[email protected]">John Doe</a>', { interpolation: { escapeValue: false }}),
'Hej <a href="mailto:[email protected]">John Doe</a>'
);
});

test('ngettext / plural', () => {
Expand Down

0 comments on commit e1d6938

Please sign in to comment.