Skip to content

Commit 2ef72e8

Browse files
meifu2027hx_meifu
andauthored
feat: implement internationalization (i18n) for English and Chinese (anomalyco#156)
Co-authored-by: hx_meifu <[email protected]>
1 parent d5a8a98 commit 2ef72e8

19 files changed

Lines changed: 1786 additions & 309 deletions

‎src/app/app.tsx‎

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ import {
6666
formatRelativeTime,
6767
groupMessageParts,
6868
isTauriRuntime,
69+
} from "./utils";
70+
import { currentLocale, setLocale, t, type Language } from "../i18n";
71+
import {
6972
isWindowsPlatform,
7073
lastUserModelFromMessages,
7174
parseModelRef,
@@ -245,7 +248,7 @@ export default function App() {
245248
if (!c || !sessionID) return;
246249

247250
setBusy(true);
248-
setBusyLabel("Running");
251+
setBusyLabel("status.running");
249252
setBusyStartedAt(Date.now());
250253
setError(null);
251254

@@ -589,14 +592,14 @@ export default function App() {
589592

590593
const label = busyLabel();
591594
// Allow creating a new session even while a run is in progress.
592-
if (busy() && label === "Running") return false;
595+
if (busy() && label === "status.running") return false;
593596

594597
// Otherwise, block during engine / connection transitions.
595598
if (
596599
busy() &&
597-
(label === "Connecting" ||
598-
label === "Starting engine" ||
599-
label === "Disconnecting")
600+
(label === "status.connecting" ||
601+
label === "status.starting_engine" ||
602+
label === "status.disconnecting")
600603
) {
601604
return true;
602605
}
@@ -666,7 +669,7 @@ export default function App() {
666669
modelID: DEFAULT_MODEL.modelID,
667670
title: DEFAULT_MODEL.modelID,
668671
description: DEFAULT_MODEL.providerID,
669-
footer: "Fallback",
672+
footer: t("settings.model_fallback", currentLocale()),
670673
isFree: true,
671674
isConnected: false,
672675
},
@@ -699,9 +702,9 @@ export default function App() {
699702
for (const model of models) {
700703
const isFree = model.cost?.input === 0 && model.cost?.output === 0;
701704
const footerBits: string[] = [];
702-
if (defaultModelID === model.id) footerBits.push("Default");
703-
if (isFree) footerBits.push("Free");
704-
if (model.capabilities?.reasoning) footerBits.push("Reasoning");
705+
if (defaultModelID === model.id) footerBits.push(t("settings.model_default", currentLocale()));
706+
if (isFree) footerBits.push(t("settings.model_free", currentLocale()));
707+
if (model.capabilities?.reasoning) footerBits.push(t("settings.model_reasoning", currentLocale()));
705708

706709
next.push({
707710
providerID: provider.id,
@@ -817,7 +820,7 @@ export default function App() {
817820
setNotionBusy(true);
818821
setNotionError(null);
819822
setNotionStatus("connecting");
820-
setNotionStatusDetail("Reload required");
823+
setNotionStatusDetail(t("settings.reload_required", currentLocale()));
821824
setNotionSkillInstalled(false);
822825

823826
try {
@@ -843,10 +846,10 @@ export default function App() {
843846
}
844847

845848
markReloadRequired("mcp");
846-
setNotionStatusDetail("Reload required");
849+
setNotionStatusDetail(t("settings.reload_required", currentLocale()));
847850
try {
848851
window.localStorage.setItem("openwork.notionStatus", "connecting");
849-
window.localStorage.setItem("openwork.notionStatusDetail", "Reload required");
852+
window.localStorage.setItem("openwork.notionStatusDetail", t("settings.reload_required", currentLocale()));
850853
window.localStorage.setItem("openwork.notionSkillInstalled", "0");
851854
} catch {
852855
// ignore
@@ -915,21 +918,21 @@ export default function App() {
915918

916919
if (mode() !== "host") {
917920
console.log("[connectMcp] ❌ mode is not host, mode=", mode());
918-
setMcpStatus("MCP connections are only available in Host mode.");
921+
setMcpStatus(t("mcp.host_mode_only", currentLocale()));
919922
return;
920923
}
921924

922925
const projectDir = workspaceProjectDir().trim();
923926
console.log("[connectMcp] projectDir:", projectDir);
924927
if (!projectDir) {
925928
console.log("[connectMcp] ❌ no projectDir");
926-
setMcpStatus("Pick a workspace folder first.");
929+
setMcpStatus(t("mcp.pick_workspace_first", currentLocale()));
927930
return;
928931
}
929932

930933
if (!isTauriRuntime()) {
931934
console.log("[connectMcp] ❌ not Tauri runtime");
932-
setMcpStatus("MCP connections require the desktop app.");
935+
setMcpStatus(t("mcp.desktop_required", currentLocale()));
933936
return;
934937
}
935938
console.log("[connectMcp] ✓ is Tauri runtime");
@@ -938,7 +941,7 @@ export default function App() {
938941
console.log("[connectMcp] activeClient:", activeClient ? "exists" : "null");
939942
if (!activeClient) {
940943
console.log("[connectMcp] ❌ no activeClient");
941-
setMcpStatus("Connect to the OpenCode server first.");
944+
setMcpStatus(t("mcp.connect_server_first", currentLocale()));
942945
return;
943946
}
944947

@@ -1026,7 +1029,7 @@ export default function App() {
10261029
setMcpAuthEntry(entry);
10271030
setMcpAuthModalOpen(true);
10281031
} else {
1029-
setMcpStatus("Reload required to activate the new MCP.");
1032+
setMcpStatus(t("mcp.reload_required_after_add", currentLocale()));
10301033
}
10311034

10321035
markReloadRequired("mcp");
@@ -1036,7 +1039,7 @@ export default function App() {
10361039
console.log("[connectMcp] ✓ done");
10371040
} catch (e) {
10381041
console.error("[connectMcp] ❌ error:", e);
1039-
setMcpStatus(e instanceof Error ? e.message : "Failed to connect MCP.");
1042+
setMcpStatus(e instanceof Error ? e.message : t("mcp.connect_failed", currentLocale()));
10401043
} finally {
10411044
setMcpConnectingName(null);
10421045
console.log("[connectMcp] finally block, connecting name cleared");
@@ -1069,7 +1072,7 @@ export default function App() {
10691072
console.log("[DEBUG] client found");
10701073
setBusy(true);
10711074
console.log("[DEBUG] busy set");
1072-
setBusyLabel("Creating new task");
1075+
setBusyLabel("status.creating_task");
10731076
console.log("[DEBUG] busy label set");
10741077
setBusyStartedAt(Date.now());
10751078
console.log("[DEBUG] busy started at set");
@@ -1126,7 +1129,7 @@ export default function App() {
11261129
mark("health ok", healthResult);
11271130
} catch (healthErr) {
11281131
mark("health FAILED", healthErr);
1129-
throw new Error("Server connection lost. Please reload.");
1132+
throw new Error(t("app.connection_lost", currentLocale()));
11301133
}
11311134

11321135
let rawResult: Awaited<ReturnType<typeof c.session.create>>;
@@ -1144,7 +1147,7 @@ export default function App() {
11441147
const session = unwrap(rawResult);
11451148
mark("session unwrapped");
11461149
// Set selectedSessionId BEFORE switching view to avoid "No session selected" flash
1147-
setBusyLabel("Loading session");
1150+
setBusyLabel("status.loading_session");
11481151
await withTimeout(
11491152
loadSessions(workspaceStore.activeWorkspaceRoot().trim()),
11501153
12_000,
@@ -1159,7 +1162,7 @@ export default function App() {
11591162
setView("session");
11601163
} catch (e) {
11611164
mark("error caught", e);
1162-
const message = e instanceof Error ? e.message : "Unknown error";
1165+
const message = e instanceof Error ? e.message : t("app.unknown_error", currentLocale());
11631166
setError(addOpencodeCacheHint(message));
11641167
} finally {
11651168
setCreatingSession(false);
@@ -1445,6 +1448,8 @@ export default function App() {
14451448
}
14461449
});
14471450

1451+
1452+
14481453
createEffect(() => {
14491454
if (typeof window === "undefined") return;
14501455
try {
@@ -1493,16 +1498,17 @@ export default function App() {
14931498
});
14941499

14951500
const headerStatus = createMemo(() => {
1496-
if (!client() || !connectedVersion()) return "Disconnected";
1497-
const bits = [`Connected · ${connectedVersion()}`];
1498-
if (sseConnected()) bits.push("Live");
1501+
if (!client() || !connectedVersion()) return t("status.disconnected", currentLocale());
1502+
const bits = [`${t("status.connected", currentLocale())} · ${connectedVersion()}`];
1503+
if (sseConnected()) bits.push(t("status.live", currentLocale()));
14991504
return bits.join(" · ");
15001505
});
15011506

15021507
const busyHint = createMemo(() => {
15031508
if (!busy() || !busyLabel()) return null;
15041509
const seconds = busySeconds();
1505-
return seconds > 0 ? `${busyLabel()} · ${seconds}s` : busyLabel();
1510+
const label = t(busyLabel()!, currentLocale());
1511+
return seconds > 0 ? `${label} · ${seconds}s` : label;
15061512
});
15071513

15081514
const localHostLabel = createMemo(() => {
@@ -1667,10 +1673,10 @@ export default function App() {
16671673
openDefaultModelPicker,
16681674
showThinking: showThinking(),
16691675
toggleShowThinking: () => setShowThinking((v) => !v),
1670-
modelVariantLabel: modelVariant() ?? "(default)",
1676+
modelVariantLabel: modelVariant() ?? t("common.default_parens", currentLocale()),
16711677
editModelVariant: () => {
16721678
const next = window.prompt(
1673-
"Model variant (provider-specific, e.g. high/max/minimal). Leave blank to clear.",
1679+
t("settings.model_variant_prompt", currentLocale()),
16741680
modelVariant() ?? ""
16751681
);
16761682
if (next == null) return;
@@ -1724,6 +1730,8 @@ export default function App() {
17241730
refreshMcpServers,
17251731
showMcpReloadBanner: reloadRequired() && reloadReasons().includes("mcp"),
17261732
reloadMcpEngine: () => reloadEngineInstance(),
1733+
language: currentLocale(),
1734+
setLanguage: setLocale,
17271735
});
17281736

17291737
return (
@@ -1821,6 +1829,7 @@ export default function App() {
18211829
resetModalText().trim().toUpperCase() === "RESET"
18221830
}
18231831
hasActiveRuns={anyActiveRuns()}
1832+
language={currentLocale()}
18241833
onClose={() => setResetModalOpen(false)}
18251834
onConfirm={confirmReset}
18261835
onTextChange={setResetModalText}
@@ -1831,6 +1840,7 @@ export default function App() {
18311840
client={client()}
18321841
entry={mcpAuthEntry()}
18331842
projectDir={workspaceProjectDir()}
1843+
language={currentLocale()}
18341844
onClose={() => {
18351845
setMcpAuthModalOpen(false);
18361846
setMcpAuthEntry(null);
@@ -1839,7 +1849,7 @@ export default function App() {
18391849
setMcpAuthModalOpen(false);
18401850
setMcpAuthEntry(null);
18411851
markReloadRequired("mcp");
1842-
setMcpStatus("OAuth completed. Reload the engine to activate the MCP.");
1852+
setMcpStatus(t("mcp.auth.oauth_completed_reload", currentLocale()));
18431853
}}
18441854
onReloadEngine={() => reloadEngineInstance()}
18451855
/>

‎src/app/components/create-workspace-modal.tsx‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { For, Show, createSignal } from "solid-js";
22

33
import { CheckCircle2, FolderPlus, Loader2, X } from "lucide-solid";
4+
import { t, currentLocale } from "../../i18n";
45

56
import Button from "./button";
67

@@ -16,33 +17,35 @@ export default function CreateWorkspaceModal(props: {
1617
subtitle?: string;
1718
confirmLabel?: string;
1819
}) {
20+
const translate = (key: string) => t(key, currentLocale());
21+
1922
const [preset, setPreset] = createSignal<"starter" | "automation" | "minimal">("starter");
2023
const [selectedFolder, setSelectedFolder] = createSignal<string | null>(null);
2124
const [pickingFolder, setPickingFolder] = createSignal(false);
2225

2326
const options = () => [
2427
{
2528
id: "starter" as const,
26-
name: "Starter workspace",
27-
desc: "Preconfigured to show you how to use plugins, templates, and skills.",
29+
name: translate("dashboard.starter_workspace"),
30+
desc: translate("dashboard.starter_workspace_desc"),
2831
},
2932
{
3033
id: "minimal" as const,
31-
name: "Empty workspace",
32-
desc: "Start with a blank folder and add what you need.",
34+
name: translate("dashboard.empty_workspace"),
35+
desc: translate("dashboard.empty_workspace_desc"),
3336
},
3437
];
3538

3639
const folderLabel = () => {
3740
const folder = selectedFolder();
38-
if (!folder) return "Choose a folder";
41+
if (!folder) return translate("dashboard.choose_folder");
3942
const parts = folder.replace(/\\/g, "/").split("/").filter(Boolean);
4043
return parts[parts.length - 1] ?? folder;
4144
};
4245

4346
const folderSubLabel = () => {
4447
const folder = selectedFolder();
45-
if (!folder) return "You will choose a directory next.";
48+
if (!folder) return translate("dashboard.choose_folder_next");
4649
return folder;
4750
};
4851

@@ -61,9 +64,9 @@ export default function CreateWorkspaceModal(props: {
6164
};
6265

6366
const showClose = () => props.showClose ?? true;
64-
const title = () => props.title ?? "Create Workspace";
65-
const subtitle = () => props.subtitle ?? "Initialize a new folder-based workspace.";
66-
const confirmLabel = () => props.confirmLabel ?? "Create Workspace";
67+
const title = () => props.title ?? translate("dashboard.create_workspace_title");
68+
const subtitle = () => props.subtitle ?? translate("dashboard.create_workspace_subtitle");
69+
const confirmLabel = () => props.confirmLabel ?? translate("dashboard.create_workspace_confirm");
6770
const isInline = () => props.inline ?? false;
6871
const submitting = () => props.submitting ?? false;
6972

@@ -91,7 +94,7 @@ export default function CreateWorkspaceModal(props: {
9194
<div class="w-6 h-6 rounded-full bg-gray-4 flex items-center justify-center text-xs">
9295
1
9396
</div>
94-
Select Folder
97+
{translate("dashboard.select_folder")}
9598
</div>
9699
<div class="ml-9">
97100
<button
@@ -110,11 +113,11 @@ export default function CreateWorkspaceModal(props: {
110113
</div>
111114
<Show
112115
when={pickingFolder()}
113-
fallback={<span class="text-xs text-gray-10">Change</span>}
116+
fallback={<span class="text-xs text-gray-10">{translate("dashboard.change")}</span>}
114117
>
115118
<span class="flex items-center gap-2 text-xs text-gray-10">
116119
<Loader2 size={12} class="animate-spin" />
117-
Opening...
120+
{translate("dashboard.opening")}
118121
</span>
119122
</Show>
120123
</div>
@@ -127,7 +130,7 @@ export default function CreateWorkspaceModal(props: {
127130
<div class="w-6 h-6 rounded-full bg-gray-4 flex items-center justify-center text-xs">
128131
2
129132
</div>
130-
Choose Preset
133+
{translate("dashboard.choose_preset")}
131134
</div>
132135
<div class={`ml-9 grid gap-3 ${!selectedFolder() ? "opacity-50" : ""}`.trim()}>
133136
<For each={options()}>
@@ -169,13 +172,13 @@ export default function CreateWorkspaceModal(props: {
169172
<div class="p-6 border-t border-gray-6 bg-gray-1 flex justify-end gap-3">
170173
<Show when={showClose()}>
171174
<Button variant="ghost" onClick={props.onClose} disabled={submitting()}>
172-
Cancel
175+
{translate("common.cancel")}
173176
</Button>
174177
</Show>
175178
<Button
176179
onClick={() => props.onConfirm(preset(), selectedFolder())}
177180
disabled={!selectedFolder() || submitting()}
178-
title={!selectedFolder() ? "Choose a folder to continue." : undefined}
181+
title={!selectedFolder() ? translate("dashboard.choose_folder_continue") : undefined}
179182
>
180183
<Show
181184
when={submitting()}

0 commit comments

Comments
 (0)