Skip to content

Commit 4e86cab

Browse files
committed
[FIX] translation: replace placeholders even if translation is not loaded
Before this commit, if the translation was not loaded, the placeholders were not replaced. closes #4242 Task: 0 X-original-commit: ca535ad Signed-off-by: Adrien Minne (adrm) <[email protected]> Signed-off-by: Pierre Rousseau (pro) <[email protected]>
1 parent 9592a2f commit 4e86cab

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/translation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class LazyTranslatedString extends String {
4040

4141
valueOf() {
4242
const str = super.valueOf();
43-
return _loaded() ? sprintf(_translate(str), ...this.values) : str;
43+
return _loaded() ? sprintf(_translate(str), ...this.values) : sprintf(str, ...this.values);
4444
}
4545
toString() {
4646
return this.valueOf();

tests/helpers/translation_helpers.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { _t } from "../../src/translation";
1+
import { _t, setTranslationMethod } from "../../src/translation";
22

33
describe("Translations", () => {
44
test("placeholders in string translation are replaced with their given value", () => {
@@ -21,4 +21,13 @@ describe("Translations", () => {
2121
test("can have named placeholders", () => {
2222
expect(_t("%(x1)s %(thing)s", { x1: "Hello", thing: "World" })).toBe("Hello World");
2323
});
24+
25+
test("should replace placeholders even if the translation is not loaded", () => {
26+
setTranslationMethod(
27+
(str, ...values) => str,
28+
() => false
29+
);
30+
const str = _t("%(x1)s %(thing)s", { x1: "Hello", thing: "World" });
31+
expect(`${str}`).toBe("Hello World");
32+
});
2433
});

0 commit comments

Comments
 (0)