From ddfee5eca2ebc5af03547fd4c21da04d53372ee4 Mon Sep 17 00:00:00 2001 From: Kaan Atakan <56063979+kaan-atakan@users.noreply.github.com> Date: Mon, 14 Feb 2022 18:24:30 +0300 Subject: [PATCH 1/3] This will fix lazy interpolation (Issue #781) (#782) * test for lazy interpolation (#781) * fix lazy interpolation (#781) Co-authored-by: Kaan Atakan --- __tests__/useTranslation.test.js | 22 ++++++++++++++++++++++ src/transCore.tsx | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/__tests__/useTranslation.test.js b/__tests__/useTranslation.test.js index ebb5f3df..4ad29e2d 100644 --- a/__tests__/useTranslation.test.js +++ b/__tests__/useTranslation.test.js @@ -44,6 +44,28 @@ describe('useTranslation', () => { expect(container.textContent).toBe(expected) }) + test('interpolation should not be lazy', () => { + const Inner = () => { + const { t } = useTranslation() + return t('common:key', { + something: 'something', + somethingElse: 'something else', + }) + } + + const expected = 'something else' + + const { container } = render( + + + + ) + expect(container.textContent).toBe(expected) + }) + test('should return the key as fallback using wrong the nested translations', () => { const i18nKey = 'ns:grandfather.parent' const expected = 'ns:grandfather.parent' diff --git a/src/transCore.tsx b/src/transCore.tsx index 426ccfa7..86528a63 100644 --- a/src/transCore.tsx +++ b/src/transCore.tsx @@ -183,7 +183,7 @@ function interpolation({ } = config.interpolation || {} const regexEnd = - suffix === '' ? '' : `\\s*,?\\s*([\\w-]+)?\\s*${escapeRegex(suffix)}` + suffix === '' ? '' : `(?:[\\s,]+([\\w-]*))?\\s*${escapeRegex(suffix)}` return Object.keys(query).reduce((all, varKey) => { const regex = new RegExp( `${escapeRegex(prefix)}\\s*${varKey}${regexEnd}`, From de6bcff6b308011ebfbe2e6b1f2e7c1516d97328 Mon Sep 17 00:00:00 2001 From: Aral Roca Gomez Date: Mon, 14 Feb 2022 16:25:45 +0100 Subject: [PATCH 2/3] Update package.json version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bd075151..b0449e2c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next-translate", - "version": "1.3.3", + "version": "1.3.4", "description": "Tiny and powerful i18n tools (Next plugin + API) to translate your Next.js pages.", "license": "MIT", "keywords": [ From cff0bd90cbef4337d8661b415c101e8e57f85997 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 14 Feb 2022 16:27:30 +0100 Subject: [PATCH 3/3] docs: add kaan-atakan as a contributor for code (#783) * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 16 ++++++++++++---- README.md | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index c516abe5..10e74bc4 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -278,7 +278,6 @@ ] }, { - "login": "testerez", "name": "Tom Esterez", "avatar_url": "https://avatars.githubusercontent.com/u/815236?v=4", @@ -288,7 +287,7 @@ ] }, { - "login": "dndhm", + "login": "dndhm", "name": "Dan Needham", "avatar_url": "https://avatars.githubusercontent.com/u/1122983?v=4", "profile": "http://www.dan-needham.com", @@ -296,7 +295,7 @@ "code", "test", "doc" - ] + ] }, { "login": "bmvantunes", @@ -306,7 +305,16 @@ "contributions": [ "code" ] - } + }, + { + "login": "kaan-atakan", + "name": "Kaan Atakan", + "avatar_url": "https://avatars.githubusercontent.com/u/56063979?v=4", + "profile": "https://github.com/kaan-atakan", + "contributions": [ + "code" + ] + } ], "contributorsPerLine": 7, "projectName": "next-translate", diff --git a/README.md b/README.md index dd3a3b36..c5fa3a9e 100644 --- a/README.md +++ b/README.md @@ -959,6 +959,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Tom Esterez

💻
Dan Needham

💻 ⚠️ 📖
Bruno Antunes

💻 +
Kaan Atakan

💻