Skip to content

Commit 45d5b5e

Browse files
authored
fix(ui): empty-string i18n params rendered the raw {placeholder} (#123474)
t() interpolation used || so a provided empty-string param fell through to the visible {placeholder} fallback meant for missing params — e.g. the devices page rendered 'Bound to {node}' whenever an agent binding was the empty string. ?? keeps the missing-param debugging aid and renders provided empties as empty.
1 parent c3d1606 commit 45d5b5e

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎ui/src/i18n/lib/translate.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ class I18nManager {
264264
}
265265

266266
if (params) {
267-
return value.replace(/\{(\w+)\}/g, (_, k) => params[k] || `{${k}}`);
267+
// ?? not ||: an empty-string param is a provided value (render empty),
268+
// while a missing param keeps the visible {placeholder} for debugging.
269+
return value.replace(/\{(\w+)\}/g, (_, k) => params[k] ?? `{${k}}`);
268270
}
269271

270272
return value;

‎ui/src/i18n/test/translate.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ describe("i18n", () => {
111111
);
112112
});
113113

114+
it("renders a provided empty-string param as empty, not the raw placeholder", () => {
115+
expect(translate.t("connection.help.copyCommandAria", { command: "" })).toBe("Copy command: ");
116+
});
117+
118+
it("keeps the visible placeholder when the param is missing", () => {
119+
expect(translate.t("connection.help.copyCommandAria", {})).toBe("Copy command: {command}");
120+
});
121+
114122
it("should fallback to English if key is missing in another locale", async () => {
115123
translate.i18n.registerTranslation("zh-CN", { common: {} } as never);
116124
await translate.i18n.setLocale("zh-CN");

0 commit comments

Comments
 (0)