From a167efe6ebac74bfed30bf54d09946d558749859 Mon Sep 17 00:00:00 2001 From: "a.mostovenko" Date: Thu, 14 Dec 2023 11:43:59 +0100 Subject: [PATCH] Skip dedenting original strings. Dedent only for msgid search --- src/index.ts | 6 +++--- tests/test_ngettext.ts | 11 ----------- tests/test_t.ts | 18 +----------------- 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7ddc7931..e8c3d9b7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -134,7 +134,7 @@ export class TTag { const trans = this.findTranslation(id, context); result = trans ? msgid2Orig(trans[0], exprs) : buildStr(strings, exprs); } - return this.maybeDedent(result); + return result; }; // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -174,10 +174,10 @@ export class TTag { const trans = this.findTranslation(id, this.ctx.getContext()); if (trans) { const pluralFn = getPluralFnForTrans(this.conf); - return this.maybeDedent(msgid2Orig(pluralFn(n, trans), args[0]._exprs)); + return msgid2Orig(pluralFn(n, trans), args[0]._exprs); } const pluralFn = this.conf.getDefaultPluralFn(); - return this.maybeDedent(pluralFn(n, forms)); + return pluralFn(n, forms); }; public gettext = (id: string) => { diff --git a/tests/test_ngettext.ts b/tests/test_ngettext.ts index ee71c9db..e759e844 100644 --- a/tests/test_ngettext.ts +++ b/tests/test_ngettext.ts @@ -56,17 +56,6 @@ describe('ngettext', () => { useLocale('en'); }); - it('should dedent multiline', () => { - const a = 1; - const others = ngettext( - msgid`test with ${a} plural - test`, - `test with ${a} plurals`, - a, - ); - expect(others).to.eql('test with 1 plural\ntest'); - }); - it('should use uk locale with uk default headers', () => { /* eslint-disable max-len */ setDefaultLang('uk'); diff --git a/tests/test_t.ts b/tests/test_t.ts index 382c2607..9f183923 100644 --- a/tests/test_t.ts +++ b/tests/test_t.ts @@ -35,22 +35,6 @@ describe('t', () => { useLocale('en'); }); - it('should dedent multiline', () => { - const result = t`multi - line - example`; - expect(result).to.eql('multi\nline\nexample'); - }); - - it('should not dedent if dedent false', () => { - setDedent(false); - const result = t`multi - line - example`; - expect(result).to.eql(result); - setDedent(true); - }); - it('should not dedent single line', () => { const result = t` single line`; expect(result).to.eql(' single line'); @@ -62,6 +46,6 @@ describe('t', () => { demo for demonstrating multiline strings`; const expected = `this is multiline\ndemo for demonstrating\nmultiline strings [translated]`; - expect(str).to.eql(expected); + expect(str).to.contain(expected); }); });