mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 04:47:03 -06:00
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:
committed by
GitHub
parent
c3d16060d4
commit
45d5b5ef51
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user