Skip to content

Commit

Permalink
Skip dedenting original strings. Dedent only for msgid search
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMost committed Dec 14, 2023
1 parent cb54d59 commit a167efe
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down
11 changes: 0 additions & 11 deletions tests/test_ngettext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
18 changes: 1 addition & 17 deletions tests/test_t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
});
});

0 comments on commit a167efe

Please sign in to comment.