diff --git a/dist/translator.js b/dist/translator.js index bb72dc2..8b05f02 100644 --- a/dist/translator.js +++ b/dist/translator.js @@ -5,8 +5,9 @@ export const trans = (key, replace, pluralize, config) => { let translation = null try { - translation = key - .split('.') + translation = + Lingua.translations[locale].php?.[key] ?? + key.split('.') .reduce((t, i) => t[i] || null, Lingua.translations[locale].php) if (translation) { @@ -16,8 +17,9 @@ export const trans = (key, replace, pluralize, config) => { } try { - translation = key - .split('.') + translation = + Lingua.translations[locale].json?.[key] ?? + key.split('.') .reduce((t, i) => t[i] || null, Lingua.translations[locale].json) if (translation) { diff --git a/tests/trans.test.js b/tests/trans.test.js index 3fd9381..be21def 100644 --- a/tests/trans.test.js +++ b/tests/trans.test.js @@ -21,7 +21,8 @@ const Lingua = { }, pl: { php: { - dashboard: 'Panel' + dashboard: 'Panel', + "Please enter your email address.": "Proszę podaj swój adres email.", } } } @@ -40,6 +41,16 @@ test('trans is translating nested object', () => { expect(trans('settings.title', {}, false, config)).toBe('Settings') }); +test("trans is translating key containing dot character", () => { + const configPl = { + Lingua: Lingua, + locale: "pl", + }; + expect(trans("Please enter your email address.", {}, false, configPl)).toBe( + "Proszę podaj swój adres email." + ); +}); + test('trans is replacing key', () => { expect(trans('replace', { user: 'World' }, false, config)).toBe('Welcome, World') });