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.
This commit is contained in:
Peter Steinberger
2026-08-14 06:26:21 -07:00
committed by GitHub
parent c3d16060d4
commit 45d5b5ef51
2 changed files with 11 additions and 1 deletions
+3 -1
View File
@@ -264,7 +264,9 @@ class I18nManager {
}
if (params) {
return value.replace(/\{(\w+)\}/g, (_, k) => params[k] || `{${k}}`);
// ?? not ||: an empty-string param is a provided value (render empty),
// while a missing param keeps the visible {placeholder} for debugging.
return value.replace(/\{(\w+)\}/g, (_, k) => params[k] ?? `{${k}}`);
}
return value;
+8
View File
@@ -111,6 +111,14 @@ describe("i18n", () => {
);
});
it("renders a provided empty-string param as empty, not the raw placeholder", () => {
expect(translate.t("connection.help.copyCommandAria", { command: "" })).toBe("Copy command: ");
});
it("keeps the visible placeholder when the param is missing", () => {
expect(translate.t("connection.help.copyCommandAria", {})).toBe("Copy command: {command}");
});
it("should fallback to English if key is missing in another locale", async () => {
translate.i18n.registerTranslation("zh-CN", { common: {} } as never);
await translate.i18n.setLocale("zh-CN");