Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/cli/ui/slash/handlers/theme.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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<string, SlashHandler> = {
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/EN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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…",
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "⚕ 健康检查 — 正在运行…",
Expand Down
17 changes: 17 additions & 0 deletions tests/slash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,7 @@ describe("handleSlash", () => {
});

afterEach(() => {
setLanguageRuntime("EN");
process.env.HOME = originalHome;
process.env.USERPROFILE = originalUserProfile;
if (originalTheme === undefined) {
Expand Down Expand Up @@ -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", () => {
Expand Down