From 206d0cd43e7801dc936cbb707f87460f0084966e Mon Sep 17 00:00:00 2001 From: w287346141 <287346141@qq.com> Date: Sun, 24 May 2026 13:19:13 +0800 Subject: [PATCH] Localize theme command feedback --- src/cli/ui/slash/handlers/theme.ts | 10 ++++++++-- src/i18n/EN.ts | 4 ++++ src/i18n/zh-CN.ts | 4 ++++ tests/slash.test.ts | 17 +++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/cli/ui/slash/handlers/theme.ts b/src/cli/ui/slash/handlers/theme.ts index ed519af..27b3874 100644 --- a/src/cli/ui/slash/handlers/theme.ts +++ b/src/cli/ui/slash/handlers/theme.ts @@ -1,4 +1,5 @@ import { resolveThemePreference, saveTheme } from "@/config.js"; +import { t } from "@/i18n/index.js"; import { type ThemeName, isThemeName, listThemeNames } from "../../theme/tokens.js"; import type { SlashHandler } from "../dispatch.js"; @@ -13,12 +14,17 @@ const theme: SlashHandler = (args) => { if (!next) return { openThemePicker: true }; if (!isThemeChoice(next)) { - return { info: `unknown theme: ${next}\navailable: ${themeChoices.join(", ")}` }; + return { + info: t("handlers.theme.unknownTheme", { + theme: next, + available: themeChoices.join(", "), + }), + }; } saveTheme(next); const active = resolveThemePreference(next, process.env.REASONIX_THEME); - return { info: `theme saved: ${next}\nactive on next launch: ${active}` }; + return { info: t("handlers.theme.saved", { theme: next, active }) }; }; export const handlers: Record = { diff --git a/src/i18n/EN.ts b/src/i18n/EN.ts index 0ac9539..97e2a21 100644 --- a/src/i18n/EN.ts +++ b/src/i18n/EN.ts @@ -761,6 +761,10 @@ export const EN: TranslationSchema = { titleStarted: "▸ naming session…", titleFailed: "▸ session title failed: {reason}", }, + theme: { + saved: "theme saved: {theme}\nactive on next launch: {active}", + unknownTheme: "unknown theme: {theme}\navailable: {available}", + }, admin: { doctorNeedsTui: "/doctor needs a TUI context (postDoctor wired).", doctorRunning: "⚕ Doctor — running health checks…", diff --git a/src/i18n/zh-CN.ts b/src/i18n/zh-CN.ts index 7afc2e3..9881014 100644 --- a/src/i18n/zh-CN.ts +++ b/src/i18n/zh-CN.ts @@ -731,6 +731,10 @@ export const zhCN: TranslationSchema = { titleStarted: "▸ 正在命名会话…", titleFailed: "▸ 会话命名失败:{reason}", }, + theme: { + saved: "主题已保存:{theme}\n下次启动时生效:{active}", + unknownTheme: "未知主题:{theme}\n可用主题:{available}", + }, admin: { doctorNeedsTui: "/doctor 需要 TUI 上下文(postDoctor 已连接)。", doctorRunning: "⚕ 健康检查 — 正在运行…", diff --git a/tests/slash.test.ts b/tests/slash.test.ts index 135865b..fd99ff5 100644 --- a/tests/slash.test.ts +++ b/tests/slash.test.ts @@ -1244,6 +1244,7 @@ describe("handleSlash", () => { }); afterEach(() => { + setLanguageRuntime("EN"); process.env.HOME = originalHome; process.env.USERPROFILE = originalUserProfile; if (originalTheme === undefined) { @@ -1273,11 +1274,27 @@ describe("handleSlash", () => { expect(loadTheme()).toBe("auto"); }); + it("localizes theme feedback in zh-CN", () => { + setLanguageRuntime("zh-CN"); + const r = handleSlash("theme", ["light"], makeLoop()); + expect(r.info).toContain("主题已保存:light"); + expect(r.info).toContain("下次启动时生效:light"); + expect(loadTheme()).toBe("light"); + }); + it("rejects unknown theme names", () => { const r = handleSlash("theme", ["solarized"], makeLoop()); expect(r.info).toMatch(/unknown theme: solarized/); expect(loadTheme()).toBeUndefined(); }); + + it("localizes unknown theme names in zh-CN", () => { + setLanguageRuntime("zh-CN"); + const r = handleSlash("theme", ["solarized"], makeLoop()); + expect(r.info).toContain("未知主题:solarized"); + expect(r.info).toContain("可用主题:auto"); + expect(loadTheme()).toBeUndefined(); + }); }); describe("/language", () => {