diff --git a/editor-web/package-lock.json b/editor-web/package-lock.json index 7e001bb6..0e27b338 100644 --- a/editor-web/package-lock.json +++ b/editor-web/package-lock.json @@ -21,9 +21,11 @@ "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "fflate": "^0.8.3", + "i18next": "^26.7.1", "lucide-react": "^1.48.0", "react": "^19.2.8", "react-dom": "^19.2.8", + "react-i18next": "^17.1.12", "react-resizable-panels": "^4.13.3", "tailwind-merge": "^3.7.0", "tailwindcss": "^4.3.3", @@ -3414,6 +3416,43 @@ "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", "license": "ISC" }, + "node_modules/html-parse-stringify": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/html-parse-stringify/-/html-parse-stringify-4.0.1.tgz", + "integrity": "sha512-0zHsZJrK7S3K2aucXWL6ycoYJ/iNtIcFHC/nYQgFklPtrv5LpJctIiSCroWZWeuoXvuyFdzp6KzjJQ+OT5MfFw==", + "license": "MIT", + "funding": { + "url": "https://locize.com" + } + }, + "node_modules/i18next": { + "version": "26.7.1", + "resolved": "https://registry.npmjs.org/i18next/-/i18next-26.7.1.tgz", + "integrity": "sha512-cX+3RRVczel/V2kCMTACckSGSpqgtWYEA6beXNYVms7dOQiHojdPYHD26lT4IKimNeoGWrLvtPgjftbRvmZJVw==", + "funding": [ + { + "type": "individual", + "url": "https://www.locize.com/i18next" + }, + { + "type": "individual", + "url": "https://www.i18next.com/how-to/faq#i18next-is-awesome.-how-can-i-support-the-project" + }, + { + "type": "individual", + "url": "https://www.locize.com" + } + ], + "license": "MIT", + "peerDependencies": { + "typescript": "^5 || ^6 || ^7" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/jiti": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.7.0.tgz", @@ -3856,6 +3895,33 @@ "react": "^19.3.0" } }, + "node_modules/react-i18next": { + "version": "17.1.12", + "resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-17.1.12.tgz", + "integrity": "sha512-Gf8riCKF/EmqQ8I1g0N5pJOLvJCkAXGAEkzOuRNHc/sBGL3dfE3WZ7+sDLrUo/kw/xdug3g48jo7M+s/SKf0HQ==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.29.7", + "html-parse-stringify": "^4.0.1", + "use-sync-external-store": "^1.6.0" + }, + "peerDependencies": { + "i18next": ">= 26.2.0", + "react": ">= 16.8.0", + "typescript": "^5 || ^6 || ^7" + }, + "peerDependenciesMeta": { + "react-dom": { + "optional": true + }, + "react-native": { + "optional": true + }, + "typescript": { + "optional": true + } + } + }, "node_modules/react-remove-scroll": { "version": "2.7.2", "resolved": "https://registry.npmjs.org/react-remove-scroll/-/react-remove-scroll-2.7.2.tgz", @@ -4099,7 +4165,7 @@ "version": "6.0.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", - "dev": true, + "devOptional": true, "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", @@ -4161,6 +4227,15 @@ } } }, + "node_modules/use-sync-external-store": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.7.0.tgz", + "integrity": "sha512-6L+EeigHMQhdaIPNIFUKwfWJSwWFQ8gJbJ2DLOs5sDIegTwR9fRxvnM3uciHKjIZhFz+KAv2emhWMRvDmMcY8A==", + "license": "MIT", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, "node_modules/vite": { "version": "8.3.1", "resolved": "https://registry.npmjs.org/vite/-/vite-8.3.1.tgz", diff --git a/editor-web/package.json b/editor-web/package.json index e1c60e12..fa923951 100644 --- a/editor-web/package.json +++ b/editor-web/package.json @@ -25,9 +25,11 @@ "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "fflate": "^0.8.3", + "i18next": "^26.7.1", "lucide-react": "^1.48.0", "react": "^19.2.8", "react-dom": "^19.2.8", + "react-i18next": "^17.1.12", "react-resizable-panels": "^4.13.3", "tailwind-merge": "^3.7.0", "tailwindcss": "^4.3.3", diff --git a/editor-web/src/App.tsx b/editor-web/src/App.tsx index f30ea218..6e6ab329 100644 --- a/editor-web/src/App.tsx +++ b/editor-web/src/App.tsx @@ -57,6 +57,7 @@ import { cn } from "@/lib/utils"; import { Boxes, Cable } from "lucide-react"; import { Viewport, type PickResult, type SelectionMode } from "@/scene/Viewport"; import type { SceneView } from "@/scene/scene-view"; +import { t, useI18n } from "@/i18n"; /** The pick intents and their keys: 1 vertex, 2 edge, 3 face, 4 solid (Plasticity's order), 5 component, 6 sketch. */ const MODES: { mode: SelectionMode; label: string; key: string }[] = [ @@ -77,6 +78,7 @@ const MANUAL_TABS = ["features", "assembly"]; const CODE_TABS = ["notebook", "module"]; export function App() { + useI18n(); // a change of language renders the whole editor again const viewRef = useRef(null); // Whether a model of the open notebook is on screen (it may be the last run's, // restored while the kernel boots): then nothing is being waited for. @@ -119,7 +121,7 @@ export function App() { // kernel is up, and a late answer of the workspace list cannot undo it. const [currentPath, setCurrentPath] = useState(null); const [kernelAlive, setKernelAlive] = useState(false); - const [status, setStatus] = useState("Connecting…"); + const [status, setStatus] = useState(() => t("Connecting…")); const [params, setParams] = useState([]); const [cells, setCells] = useState([]); @@ -222,7 +224,7 @@ export function App() { const handleStop = useCallback(() => { socketRef.current?.send({ type: "interrupt.request" }); setLoading(null); - log.push("info", "stop requested"); + log.push("info", t("stop requested")); log.resetBatch(); }, [log.push, log.resetBatch]); @@ -256,9 +258,9 @@ export function App() { framedNotebook.current = name; } setSceneVersion((version) => version + 1); - log.push("ok", `model shown: ${preview.nodes.length} ${preview.nodes.length === 1 ? "part" : "parts"}`); + log.push("ok", preview.nodes.length === 1 ? t("model shown: 1 part") : t("model shown: {{count}} parts", { count: preview.nodes.length })); } catch (error) { - log.push("error", error instanceof Error ? error.message : "unable to open the preview"); + log.push("error", error instanceof Error ? error.message : t("unable to open the preview")); } }, [log.push]); @@ -284,9 +286,9 @@ export function App() { refreshFeatures(); // No notebook: nothing to wait for. Else the model is on its way. if (hasModel.current) return; - const stage = envelope["notebook"] ? (envelope["kernel"] ? "building the model" : "starting the kernel") : null; + const stage = envelope["notebook"] ? (envelope["kernel"] ? t("building the model") : t("starting the kernel")) : null; setLoading(stage); - setStatus(stage ? `${stage[0].toUpperCase()}${stage.slice(1)}…` : "No notebook yet: create one in the workspace tab"); + setStatus(stage ? `${stage}…` : t("No notebook yet: create one in the workspace tab")); refreshWorkspace(); }); @@ -321,10 +323,10 @@ export function App() { refreshFeatures(); setNotebook(String(envelope["notebook"] ?? "")); setCurrentPath((envelope["path"] as string) ?? null); - setStatus(`opening ${envelope["notebook"]}…`); - setLoading(`opening ${envelope["notebook"]}`); + setStatus(`${t("opening {{name}}", { name: envelope["notebook"] })}…`); + setLoading(t("opening {{name}}", { name: envelope["notebook"] })); log.resetBatch(); - log.push("info", `opening ${envelope["notebook"]}`); + log.push("info", t("opening {{name}}", { name: envelope["notebook"] })); setSceneVersion((version) => version + 1); refreshWorkspace(); }); @@ -371,7 +373,7 @@ export function App() { // The server dropped an edit made on a cell that had changed on disk. socket.on("cell.conflict", (envelope) => { const mine = String(envelope["mine"] ?? ""); - log.push("error", `a cell changed on disk while you were editing it: kept the file's version. Your unsaved text was:\n${mine.length > 600 ? `${mine.slice(0, 600)}…` : mine}`); + log.push("error", `${t("a cell changed on disk while you were editing it: kept the file's version. Your unsaved text was:")}\n${mine.length > 600 ? `${mine.slice(0, 600)}…` : mine}`); }); socket.on("notebook.features", (envelope) => setFeatures((envelope["features"] as NotebookFeature[]) ?? [])); socket.on("workplanes", (envelope) => setWorkplanes(parseWorkplanes(envelope["workplanes"]))); @@ -387,7 +389,7 @@ export function App() { const nextPartial = parsePartial(envelope["partial"]); if (nextPartial && !samePartial(partialRef.current, nextPartial)) { const { title, reason } = describePartial(nextPartial); - log.push("info", `showing ${title.charAt(0).toLowerCase()}${title.slice(1)}: ${reason}`); + log.push("info", t("showing {{what}}: {{reason}}", { what: title, reason })); } partialRef.current = nextPartial; setPartial(nextPartial); @@ -425,18 +427,18 @@ export function App() { setLoading(null); } } else if (typeof envelope["info"] === "string") { - setStatus(envelope["info"]); - log.push("info", envelope["info"]); + setStatus(t(envelope["info"])); + log.push("info", t(envelope["info"])); setLoading(null); // a notice ends a wait as well (an empty notebook has no model to wait for) } else if (typeof envelope["working"] === "string") { setStatus(envelope["working"]); log.push("run", envelope["working"]); setLoading(envelope["working"].replace(/…$/, "")); } else if (typeof envelope["exported"] === "string") { - setStatus(`exported ${envelope["exported"]}`); + setStatus(t("exported {{path}}", { path: envelope["exported"] })); log.push("ok", `exported ${envelope["exported"]}`); } else if (typeof envelope["created"] === "string") { - setStatus(`created ${envelope["created"]}`); + setStatus(t("created {{path}}", { path: envelope["created"] })); log.push("ok", `created ${envelope["created"]}`); } }); @@ -505,7 +507,7 @@ export function App() { }, [resolveFace], ); - const refusal = (type: string | null) => `This face is ${type ? `a ${type.toLowerCase()}` : "curved"}: a sketch needs a flat face. Pick a flat face or a datum plane.`; + const refusal = (type: string | null) => (type ? t("This face is a {{type}}: a sketch needs a flat face. Pick a flat face or a datum plane.", { type: type.toLowerCase() }) : t("This face is curved: a sketch needs a flat face. Pick a flat face or a datum plane.")); /** While the sketch plane is being chosen a face pick means "sketch on this face" and never reaches the selection. */ const pickSketchFace = useCallback( @@ -768,7 +770,7 @@ export function App() { const workplaneFromSelection = useCallback(async () => { const request = workplaneRequest(selectionRef.current); if (!request) { - setBarNote("A workplane needs one flat face, a face and an edge, two parallel faces, three vertices or one edge."); + setBarNote(t("A workplane needs one flat face, a face and an edge, two parallel faces, three vertices or one edge.")); return; } setBarNote(null); @@ -853,10 +855,10 @@ export function App() { /** The bases a workplane can be placed on: the datum planes, every workplane of the notebook, and the picked face. */ const placeBases = useMemo(() => { - if (placing?.kind === "connector" && placing.face) return [{ value: "face", label: "picked face", frame: placing.face.frame }]; + if (placing?.kind === "connector" && placing.face) return [{ value: "face", label: t("picked face"), frame: placing.face.frame }]; const out: PlaceBase[] = (["XY", "XZ", "YZ"] as const).map((name) => ({ value: name, label: name, frame: NAMED_FRAMES[name] })); for (const wp of workplanes) out.push({ value: wp.name, label: wp.name, frame: { origin: wp.origin, x_axis: wp.x_axis, y_axis: wp.y_axis, normal: wp.normal } }); - if (placing?.face) out.push({ value: "face", label: "picked face", frame: placing.face.frame }); + if (placing?.face) out.push({ value: "face", label: t("picked face"), frame: placing.face.frame }); return out; }, [workplanes, placing?.face, placing?.kind]); const placeBase = placeBases.find((item) => item.value === placing?.base) ?? placeBases[0]; @@ -869,7 +871,7 @@ export function App() { const face = items.length === 1 && items[0].kind === "face" ? items[0] : null; const frame = face ? faceFrame(face.properties) : null; if (face && !frame) { - setBarNote("That face is not flat: a workplane lies on a plane. Pick a flat face, or nothing to place one on the active workplane."); + setBarNote(t("That face is not flat: a workplane lies on a plane. Pick a flat face, or nothing to place one on the active workplane.")); return; } const taken = gui.state?.taken ?? []; @@ -887,7 +889,7 @@ export function App() { const face = items.length === 1 && items[0].kind === "face" ? items[0] : null; const frame = face ? connectorFrameFromFace(face) : null; if (!face || !frame) { - setBarNote("A connector is placed on one flat face: pick it first (face mode)."); + setBarNote(t("A connector is placed on one flat face: pick it first (face mode).")); return; } setBarNote(null); @@ -1162,9 +1164,9 @@ export function App() { /** A command from the assembly panel: rejects with the server's message (shown in the panel). */ const runPanelCommand = useCallback( async (command: FeatureCommand) => { - if (noNotebook()) throw new Error("No notebook is open: create one first."); + if (noNotebook()) throw new Error(t("No notebook is open: create one first.")); const result = await gui.run(command); - log.push("ok", command.op === "set_connectors" ? "connectors set" : `${command.op} ${result.name}`); + log.push("ok", command.op === "set_connectors" ? t("connectors set") : `${command.op} ${result.name}`); if (isCellCommand(command)) assertCellRan(result); }, [gui.run, log.push, noNotebook], @@ -1245,15 +1247,15 @@ export function App() { // -- actions ----------------------------------------------------------------------- const handleOpen = (path: string) => { - setStatus(`opening ${path}…`); + setStatus(`${t("opening {{name}}", { name: path })}…`); openNotebook(path).catch((error) => { - log.push("error", `open failed: ${error.message}`); + log.push("error", t("open failed: {{reason}}", { reason: error.message })); setLoading(null); }); }; const handleCreate = async (name: string, kind: "part" | "assembly") => { - setStatus(`creating ${name}…`); + setStatus(`${t("creating {{name}}", { name })}…`); await newNotebook(name, kind); // the server opens it: show its features (manual mode) or its cells (code mode) setLeftTab(mode === "manual" ? "features" : "notebook"); @@ -1268,14 +1270,14 @@ export function App() { {mode === "manual" ? ( <> - features - assembly - workspace + {t("features")} + {t("assembly")} + {t("workspace")} ) : ( <> - notebook - workspace + {t("notebook")} + {t("workspace")} {moduleView && {moduleView.name}} )} @@ -1334,7 +1336,7 @@ export function App() { onCreate={handleCreate} onDelete={async (path) => { const { trash } = await deleteNotebook(path); - log.push("ok", `deleted ${path} (kept in ${trash})`); + log.push("ok", t("deleted {{path}} (kept in {{trash}})", { path, trash })); }} /> @@ -1362,20 +1364,20 @@ export function App() { : "border-transparent text-muted-foreground hover:border-input hover:text-foreground", )} onClick={() => setSelectionMode(mode)} - title={`${label} (${key})`} + title={`${t(label)} (${key})`} > - {label} + {t(label)} {key} ))} {!floating && } - {!floating && ctrl+click: add} + {!floating && {t("ctrl+click: add")}} ); @@ -1400,7 +1402,7 @@ export function App() { running={running} onStop={handleStop} onRunAll={() => { - setLoading("running all cells"); + setLoading(t("running all cells")); socketRef.current?.send({ type: "rerun.request" }); }} /> diff --git a/editor-web/src/components/ActionBar.tsx b/editor-web/src/components/ActionBar.tsx index b7086c46..cb1e1152 100644 --- a/editor-web/src/components/ActionBar.tsx +++ b/editor-web/src/components/ActionBar.tsx @@ -4,6 +4,7 @@ import { useEffect, useLayoutEffect, useRef, useState } from "react"; import { Button } from "@/components/ui/button"; import { enterRunsFirst, placeBar, type Size } from "@/lib/action-bar"; import { cn } from "@/lib/utils"; +import { t } from "@/i18n"; export type BarAction = { id: string; @@ -71,7 +72,7 @@ export function ActionBar({
(action.disabled ? setWhy({ id: action.id, text: action.disabled }) : action.run())} style={action.disabled ? { opacity: 0.45 } : undefined} > {Icon && } - {action.label} + {t(action.label)} {isFirst && enter && enter} ); diff --git a/editor-web/src/components/CellEditor.tsx b/editor-web/src/components/CellEditor.tsx index ff5b1c7b..770de1e5 100644 --- a/editor-web/src/components/CellEditor.tsx +++ b/editor-web/src/components/CellEditor.tsx @@ -23,6 +23,7 @@ import { createSettler, SETTLE_MS } from "@/lib/settle"; import { cadTheme } from "@/lib/cm-theme"; import { sdkCompletion } from "@/lib/sdk-complete"; import { cn } from "@/lib/utils"; +import { t } from "@/i18n"; export type NotebookCell = { id: string; @@ -230,22 +231,22 @@ export function CellEditor({ }, [armed]); if (cells.length === 0) { - return

Waiting for the kernel to publish cells…

; + return

{t("Waiting for the kernel to publish cells…")}

; } const allCollapsed = cells.every((cell) => collapsed.has(cell.id)); return (
- {cells.length} cells + {cells.length === 1 ? t("1 cell") : t("{{count}} cells", { count: cells.length })}
@@ -288,7 +289,7 @@ function CellGap({ after, onInsert }: { after: string | null; onInsert: (after:
- {dirty && } - {cell.status === "running" && running} - {cell.status === "queued" && queued} - {failed && failed} - {cell.blocked && !failed && blocked} - {stale && !failed && stale} - {cell.readonly && function} + {dirty && } + {cell.status === "running" && {t("running")}} + {cell.status === "queued" && {t("queued")}} + {failed && {t("failed")}} + {cell.blocked && !failed && {t("blocked")}} + {stale && !failed && {t("stale")}} + {cell.readonly && {t("function")}} - + {/* One button, two states: run, and while the kernel is running the cell, stop. */} socket?.send({ type: "param.revert", names: params.filter((p) => p.modified).map((p) => p.id) }) } > - revert + {t("revert")}
)} diff --git a/editor-web/src/components/CommandBar.tsx b/editor-web/src/components/CommandBar.tsx index be4094b8..22a44172 100644 --- a/editor-web/src/components/CommandBar.tsx +++ b/editor-web/src/components/CommandBar.tsx @@ -3,6 +3,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { commandGroups, pushRecent, searchCommands, type Command } from "@/lib/commands"; import { cn } from "@/lib/utils"; +import { t } from "@/i18n"; const DOCK_KEY = "sca.commandbar.dock"; const RECENT_KEY = "sca.commandbar.recent"; @@ -135,11 +136,11 @@ export function CommandBar({ commands, fit, hint, belowTop = false }: { commands
); @@ -147,12 +148,12 @@ export function CommandBar({ commands, fit, hint, belowTop = false }: { commands return (
-
+
{shown.length > 0 && (
    run(command)} > {Icon ? : } - {command.label} - {command.description} - 0 ? "font-bold" : "opacity-70")}>{fit && fit(command) > 0 ? "fits selection" : command.group} + {t(command.label)} + {command.description ? t(command.description) : null} + 0 ? "font-bold" : "opacity-70")}>{fit && fit(command) > 0 ? t("fits selection") : t(command.group)} ); })} @@ -205,7 +206,7 @@ export function CommandBar({ commands, fit, hint, belowTop = false }: { commands setOpen(!same); }} > - {name} + {t(name)} ))}
@@ -217,8 +218,8 @@ export function CommandBar({ commands, fit, hint, belowTop = false }: { commands value={query} role="combobox" aria-expanded={open} - aria-label="Search operations" - placeholder="Search operations" + aria-label={t("Search operations")} + placeholder={t("Search operations")} spellCheck={false} className="h-6 w-full border-2 border-input bg-background pl-6 pr-[78px] text-[12px] placeholder:text-muted-foreground focus-visible:border-focus focus-visible:outline-none" onChange={(event) => { @@ -231,13 +232,13 @@ export function CommandBar({ commands, fit, hint, belowTop = false }: { commands onKeyDown={onInputKey} /> {!query && ( - / or Ctrl+K + {t("/ or Ctrl+K")} )} - -
diff --git a/editor-web/src/components/CurveDrawer.tsx b/editor-web/src/components/CurveDrawer.tsx index 0ba556df..8f3e2883 100644 --- a/editor-web/src/components/CurveDrawer.tsx +++ b/editor-web/src/components/CurveDrawer.tsx @@ -25,6 +25,7 @@ import { rayThrough } from "@/scene/camera-projection"; import { OVERLAY_LAYER } from "@/scene/renderer/brep-renderer"; import { pointSprites } from "@/scene/point-sprites"; import type { SceneView } from "@/scene/scene-view"; +import { t } from "@/i18n"; const EMPTY: CurveDoc = { points: [], curves: [] }; const PATH = "#2563eb"; @@ -348,14 +349,14 @@ export function CurveDrawer({ const hint = doc.points.length === 0 - ? "Click the first point." + ? t("Click the first point.") : tool === "arc" ? pending.length === 0 - ? "Click a point the arc passes through." - : "Click where the arc ends." + ? t("Click a point the arc passes through.") + : t("Click where the arc ends.") : tool === "spline" - ? "Click the points the spline passes through; another tool or Enter ends it." - : "Click where the line ends."; + ? t("Click the points the spline passes through; another tool or Enter ends it.") + : t("Click where the line ends."); return ( <> @@ -367,23 +368,23 @@ export function CurveDrawer({ )}
- 3D curve - setName(event.target.value)} /> + {t("3D curve")} + setName(event.target.value)} /> {TOOLS.map((item) => ( ))} - on - setPlaneName(event.target.value)}> {planes.map((item) => (
- {hint} Snaps to vertices, edge midpoints, workplane origins, its own points and the grid. Tab: next plane · ⌫: back + {hint} {t("Snaps to vertices, edge midpoints, workplane origins, its own points and the grid. Tab: next plane · ⌫: back")}
- {doc.curves.length} {doc.curves.length === 1 ? "segment" : "segments"} · {nextId(doc.points.map((p) => p.id), "p")} + {doc.curves.length === 1 ? t("1 segment") : t("{{count}} segments", { count: doc.curves.length })} · {nextId(doc.points.map((p) => p.id), "p")}
{error && ( diff --git a/editor-web/src/components/Dock.tsx b/editor-web/src/components/Dock.tsx index 2e23c21d..adb70a81 100644 --- a/editor-web/src/components/Dock.tsx +++ b/editor-web/src/components/Dock.tsx @@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from "react"; import { cn } from "@/lib/utils"; import type { LogEntry, LogLevel, RunBatch } from "@/lib/runlog"; +import { t } from "@/i18n"; const INK: Record = { info: "text-muted-foreground", @@ -61,11 +62,11 @@ export function Dock({ const percent = batch && batch.total > 0 ? Math.round((batch.done / batch.total) * 100) : 0; return ( -
+
{open && (
{entries.length === 0 ? ( -

Nothing yet. Runs, reloads and errors are listed here.

+

{t("Nothing yet. Runs, reloads and errors are listed here.")}

) : ( entries.map((entry) => (

@@ -82,20 +83,20 @@ export function Dock({ type="button" className="flex min-w-0 flex-1 items-center gap-2 self-stretch text-left" onClick={() => setOpen((value) => !value)} - title={open ? "Close the log" : "Open the log"} + title={open ? t("Close the log") : t("Open the log")} > {open ? : } - log + {t("log")} {batch ? ( <> - re-evaluating {batch.done}/{batch.total} + {t("re-evaluating {{done}}/{{total}}", { done: batch.done, total: batch.total })} - {batch.current ? `${batch.current} · ` : batch.done >= batch.total ? "building the model · " : ""} + {batch.current ? `${batch.current} · ` : batch.done >= batch.total ? `${t("building the model")} · ` : ""} {(Math.max(0, tick - batch.startedAt) / 1000).toFixed(1)} s @@ -107,12 +108,12 @@ export function Dock({ {errors > 0 && ( - {errors} {errors === 1 ? "error" : "errors"} + {errors === 1 ? t("1 error") : t("{{count}} errors", { count: errors })} )} {note && {note}}

@@ -431,10 +432,10 @@ function FeatureForm({
{holeDraft && view && } @@ -519,7 +520,7 @@ function SlotWidget({ const raw = form[slot.name]; if (slot.kind === "enum" && slot.name === OPERATION_SLOT && slot.options?.some((option) => option.value === "join")) { const { options: choices, note } = operationOptions(slot.options, combine, edit); - return set(slot.name, value)} icons={OPERATION_ICONS} label={slot.label} note={note} />; + return set(slot.name, value)} icons={OPERATION_ICONS} label={t(slot.label)} note={note} />; } if (slot.kind === "body" && slot.name === TARGET_SLOT) { const shown = targetDisplay(combine, edit, typeof raw === "string" ? raw : ""); @@ -527,7 +528,7 @@ function SlotWidget({ if (shown.kind === "fixed") { return ( - Combined with: {shown.name} + {t("Combined with:")} {shown.name} ); } @@ -545,18 +546,18 @@ function SlotWidget({ {(options ?? slot.options ?? []).map((option) => ( - {option.label} + {t(option.label)} ))} {flip && (
- - pushes {flip.against ? "against" : "along"} the sketch normal ({flip.axis}); the arrow in the viewport shows it + {flip.against ? t("pushes against the sketch normal ({{axis}}); the arrow in the viewport shows it", { axis: flip.axis }) : t("pushes along the sketch normal ({{axis}}); the arrow in the viewport shows it", { axis: flip.axis })}
)} @@ -568,12 +569,12 @@ function SlotWidget({ return ( set(slot.name, value)}> - + {choices.map((choice) => ( @@ -669,7 +670,7 @@ function SlotWidget({ {hex ? hex : slot.optional ? "unchanged" : "none"} {hex && slot.optional && ( )}
@@ -685,15 +686,15 @@ function SlotWidget({
- Sketch: {chosen ? {chosen.name} : none picked} + {t("Sketch:")} {chosen ? {chosen.name} : {t("none picked")}} -
{chosen && ( - Plane {profilePlaneLabel(chosen)}, normal {chosen.normal} + {t("Plane {{plane}}, normal", { plane: profilePlaneLabel(chosen) })} {chosen.normal} )} {summary && ( - This sketch has several loops; it uses what was chosen in the sketch ({summary}). + {t("This sketch has several loops; it uses what was chosen in the sketch ({{summary}}).", { summary })} )}
@@ -747,24 +748,24 @@ function SlotWidget({ /> ); case "select": { - const noun = slot.entity === "edge" ? "Edges" : "Faces"; + const noun = slot.entity === "edge" ? t("Edges") : t("Faces"); const loading = filterSelection(selection, slot.entity ?? "face").some((item) => !isDescribed(item)); return (
{kept ? ( <> - {noun}: kept from the recipe + {noun}: {t("kept from the recipe")} ) : ( <> - {noun}: {picks} picked - {loading && (loading details…)} + {noun}: {t("{{count}} picked", { count: picks })} + {loading && {t("(loading details…)")}} )} - Pick {noun.toLowerCase()} in the viewport; Ctrl/Cmd+click adds.{kept ? " Pick again to replace them." : ""} + {slot.entity === "edge" ? t("Pick edges in the viewport; Ctrl/Cmd+click adds.") : t("Pick faces in the viewport; Ctrl/Cmd+click adds.")}{kept ? ` ${t("Pick again to replace them.")}` : ""}
); diff --git a/editor-web/src/components/FeatureTree.tsx b/editor-web/src/components/FeatureTree.tsx index cbbbe0f4..13ea850b 100644 --- a/editor-web/src/components/FeatureTree.tsx +++ b/editor-web/src/components/FeatureTree.tsx @@ -8,16 +8,17 @@ import { plainLabel } from "@/lib/commands"; import { candidateLabel, fetchRefStatus, refState, refTone, type Catalog, type FeatureRow, type FeatureState, type RefStatus, type Spec } from "@/lib/features"; import type { SketchInfo } from "@/lib/sketch-scene"; import { cn } from "@/lib/utils"; +import { t } from "@/i18n"; /** Undo and redo with their counts. */ export function UndoRedo({ state, busy, onUndo, onRedo }: { state: Pick; busy?: boolean; onUndo: () => void; onRedo: () => void }) { return ( - - ); @@ -59,7 +60,7 @@ export function ReferenceHealth({ cell, version, busy, onRepair }: { cell: strin ); return () => void (live = false); }, [cell, version]); - if (failure) return

references: {failure}

; + if (failure) return

{t("references:")} {failure}

; if (!status || status.badge === null) return null; return (
@@ -74,7 +75,7 @@ export function ReferenceHealth({ cell, version, busy, onRepair }: { cell: strin
{row.candidates.map((candidate, choice) => ( ))} @@ -140,23 +141,23 @@ export function FeatureTree({ return (
- features {state.features.length > 0 && `(${state.features.length})`} + {t("features")} {state.features.length > 0 && `(${state.features.length})`}
{stale && state.tip && (
- The product still builds from {stale.body}. + {t("The product still builds from")} {stale.body}.
)} {error &&
{error}
} {state.features.length === 0 ? ( -

No features yet. Add a Box or another operation above; each one becomes an ordinary cell in the notebook.

+

{t("No features yet. Add a Box or another operation from the command bar; each one becomes an ordinary cell in the notebook.")}

) : (
    {state.features.map((feature) => { @@ -188,14 +189,14 @@ export function FeatureTree({ {feature.index} {feature.slug} {isProduct && ( - - product + + {t("product")} )} - {feature.role} + {t(feature.role)} {sketch && sketch.usedBy.length > 0 && ( - - used + + {t("used")} )} {spec ? plainLabel(spec.id, spec.label) : feature.gui ? feature.gui.spec.replace(/_/g, " ") : "code"} @@ -212,15 +213,15 @@ export function FeatureTree({ className="h-6 w-6" data-testid={`sketch-eye-${sketch.name}`} aria-pressed={!hiddenSketch} - aria-label={hiddenSketch ? `show ${sketch.name} in the viewport` : `hide ${sketch.name} in the viewport`} - title={hiddenSketch ? "Show this sketch in the viewport" : "Hide this sketch in the viewport"} + aria-label={hiddenSketch ? t("show {{name}} in the viewport", { name: sketch.name }) : t("hide {{name}} in the viewport", { name: sketch.name })} + title={hiddenSketch ? t("Show this sketch in the viewport") : t("Hide this sketch in the viewport")} onClick={() => sketches?.onToggleHidden(sketch.name)} > {hiddenSketch ? : } )} - - @@ -230,8 +231,8 @@ export function FeatureTree({ variant={armed === feature.cell ? "destructive" : "ghost"} className="h-6 w-6" disabled={busy} - aria-label={armed === feature.cell ? `confirm delete ${feature.slug}` : `delete ${feature.slug}`} - title={armed === feature.cell ? "Click again to delete" : "Delete this feature"} + aria-label={armed === feature.cell ? t("confirm delete {{name}}", { name: feature.slug }) : t("delete {{name}}", { name: feature.slug })} + title={armed === feature.cell ? t("Click again to delete") : t("Delete this feature")} onClick={() => { if (armed === feature.cell) { setArmed(null); diff --git a/editor-web/src/components/FloatingPanels.tsx b/editor-web/src/components/FloatingPanels.tsx index f401915a..d67ae6a3 100644 --- a/editor-web/src/components/FloatingPanels.tsx +++ b/editor-web/src/components/FloatingPanels.tsx @@ -2,6 +2,7 @@ import { useState, type ReactNode } from "react"; import { ChevronsLeft, ChevronsRight, ListTree, ScanSearch } from "lucide-react"; import { cn } from "@/lib/utils"; +import { t } from "@/i18n"; /** Whether a card is open, remembered in this browser (a convenience: it reads as open when storage is unavailable). */ function useRemembered(key: string): [boolean, (open: boolean) => void] { @@ -66,17 +67,17 @@ export function FloatingPanels({
) : ( - )} {leftNotice &&
{leftNotice}
} @@ -89,17 +90,17 @@ export function FloatingPanels({
) : ( - )} {rightNotice &&
{rightNotice}
} diff --git a/editor-web/src/components/Header.tsx b/editor-web/src/components/Header.tsx index f3a4b71d..366ffefe 100644 --- a/editor-web/src/components/Header.tsx +++ b/editor-web/src/components/Header.tsx @@ -1,4 +1,4 @@ -import { Monitor, Moon, Play, Square, Sun } from "lucide-react"; +import { Languages, Monitor, Moon, Play, Square, Sun } from "lucide-react"; import type { ThemePreference } from "@/lib/theme"; @@ -7,6 +7,7 @@ import { Button } from "@/components/ui/button"; import { UndoRedo } from "@/components/FeatureTree"; import { ModeSwitch, type EditorMode } from "@/components/ModeSwitch"; import type { FeatureState } from "@/lib/features"; +import { LANGUAGES, setLanguage, useI18n } from "@/i18n"; /** Top bar: which notebook is open, whether its kernel is alive, and the * model's last message. Everything else lives on the cells. */ @@ -45,7 +46,9 @@ export function Header({ /** A sketch is open or the panels are moving: the mode cannot change now. */ modeLocked: boolean; }) { + const { t, language } = useI18n(); const failing = status.startsWith("error"); + const nextLanguage = LANGUAGES[(LANGUAGES.findIndex((item) => item.code === language) + 1) % LANGUAGES.length]; return (
SimpleCAD @@ -56,11 +59,11 @@ export function Header({ {kind && kind !== "helper" && {kind}} ) : ( - no notebook + {t("no notebook")} )} {running ? ( - ) : ( - )} +
diff --git a/editor-web/src/components/Inspector.tsx b/editor-web/src/components/Inspector.tsx index ff2bd929..fd63fe64 100644 --- a/editor-web/src/components/Inspector.tsx +++ b/editor-web/src/components/Inspector.tsx @@ -2,6 +2,7 @@ import { Badge } from "@/components/ui/badge"; import { ScrollArea } from "@/components/ui/scroll-area"; import { JsonTree } from "@/components/JsonTree"; import type { SelectionItem } from "@/lib/selection"; +import { t } from "@/i18n"; /** Right-hand inspector: what is selected in the viewport, each item with * the variable the selection cell assigns it to and its data as a tree. */ @@ -10,14 +11,13 @@ export function Inspector({ selection, sketches = [] }: { selection: SelectionIt return (
- selection + {t("selection")} {count > 0 && {count}}
{count === 0 ? (

- Click a solid, face, edge, vertex or sketch in the viewport (pick the kind with the chips above it). - Ctrl/Cmd+click adds to the selection; picked model items are written to the notebook as{" "} + {t("Click a solid, face, edge, vertex or sketch in the viewport (pick the kind with the chips). Ctrl/Cmd+click adds to the selection; picked model items are written to the notebook as")}{" "} selected_item.

) : ( @@ -46,16 +46,16 @@ export function Inspector({ selection, sketches = [] }: { selection: SelectionIt
- - - {item.definitionId && } + + + {item.definitionId && }
- {item.pending &&

loading details…

} + {item.pending &&

{t("loading details…")}

} {(item.properties || item.geometry) && (
- {item.properties && } - {item.geometry && } - {item.tags && item.tags.length > 0 && } + {item.properties && } + {item.geometry && } + {item.tags && item.tags.length > 0 && }
)} diff --git a/editor-web/src/components/LoadingMask.tsx b/editor-web/src/components/LoadingMask.tsx index f6abf553..1750c003 100644 --- a/editor-web/src/components/LoadingMask.tsx +++ b/editor-web/src/components/LoadingMask.tsx @@ -1,6 +1,7 @@ import { useEffect, useRef, useState } from "react"; import { cn } from "@/lib/utils"; +import { t } from "@/i18n"; /** Cells of the 3x3 spinner that form its ring, clockwise from the top left. */ const RING = [0, 1, 2, 5, 8, 7, 6, 3]; @@ -50,7 +51,7 @@ export function LoadingMask({ active, message, theme }: { active: boolean; messa
- loading + {t("loading")} {minutes}:{seconds} diff --git a/editor-web/src/components/ModeSwitch.tsx b/editor-web/src/components/ModeSwitch.tsx index 0dacd32b..a6e0b4dc 100644 --- a/editor-web/src/components/ModeSwitch.tsx +++ b/editor-web/src/components/ModeSwitch.tsx @@ -1,4 +1,5 @@ import { cn } from "@/lib/utils"; +import { t } from "@/i18n"; export type EditorMode = "manual" | "code"; @@ -10,7 +11,7 @@ const OPTIONS: { value: EditorMode; label: string; hint: string }[] = [ /** The big two-position switch of the top bar: manual mode on the left, code mode on the right. */ export function ModeSwitch({ mode, onChange, disabled }: { mode: EditorMode; onChange: (mode: EditorMode) => void; disabled?: boolean }) { return ( -
+
option.value !== mode && onChange(option.value)} @@ -31,7 +32,7 @@ export function ModeSwitch({ mode, onChange, disabled }: { mode: EditorMode; onC mode === option.value ? "text-primary-foreground" : "text-muted-foreground hover:text-foreground", )} > - {option.label} + {t(option.label)} ))}
diff --git a/editor-web/src/components/ModuleView.tsx b/editor-web/src/components/ModuleView.tsx index 7ae7b509..47d75414 100644 --- a/editor-web/src/components/ModuleView.tsx +++ b/editor-web/src/components/ModuleView.tsx @@ -10,6 +10,7 @@ import { ParamControl, type ParamMeta, type ParamValue } from "@/components/Para import { cadTheme } from "@/lib/cm-theme"; import { createSettler, SETTLE_MS } from "@/lib/settle"; import { sdkCompletion } from "@/lib/sdk-complete"; +import { t } from "@/i18n"; /** A local module of the workspace (shared dimensions, helpers): what the * server sends as the `module` envelope. */ @@ -103,12 +104,12 @@ export function ModuleView({ used by {module.used_by.map((path) => path.replace(/\.py$/, "")).join(", ")} ) : ( - unused + {t("unused")} )}
-

Every operation and drawing is written into a notebook. Create one first (it starts empty).

+

{t("Every operation and drawing is written into a notebook. Create one first (it starts empty).")}

{ @@ -47,10 +48,10 @@ export function NewNotebookPrompt({ onCreate, onClose }: { onCreate: (name: stri value={name} onChange={(event) => setName(event.target.value)} className="min-w-0 flex-1 border border-border bg-background px-2 py-1 font-mono" - aria-label="Notebook name" + aria-label={t("Notebook name")} />
{error &&

{error}

} diff --git a/editor-web/src/components/NotebookList.tsx b/editor-web/src/components/NotebookList.tsx index a9e6b87a..09c31a3f 100644 --- a/editor-web/src/components/NotebookList.tsx +++ b/editor-web/src/components/NotebookList.tsx @@ -6,6 +6,7 @@ import { Button } from "@/components/ui/button"; import { ScrollArea } from "@/components/ui/scroll-area"; import { cn } from "@/lib/utils"; import type { ModuleRow, NotebookRow } from "@/lib/api"; +import { t } from "@/i18n"; /** Names the template accepts: the notebook's id and its file name. */ const NAME = /^[A-Za-z_][A-Za-z0-9_-]*$/; @@ -43,14 +44,14 @@ export function NotebookList({ return (
- notebooks + {t("notebooks")}
{(adding || empty) && ( @@ -63,7 +64,7 @@ export function NotebookList({
)} @@ -110,7 +111,7 @@ export function NotebookList({ {row.name} {row.kind} - {row.error && error} + {row.error && {t("error")}} {row.uses && row.uses.length > 0 && ( @@ -138,7 +139,7 @@ export function NotebookList({ > {module.path} - used by {module.used_by.map((path) => path.replace(/\.py$/, "")).join(", ")} + {t("used by {{users}}", { users: module.used_by.map((path) => path.replace(/\.py$/, "")).join(", ") })} @@ -175,15 +176,15 @@ function NewEntry({ const submit = async () => { const value = name.trim(); - if (!NAME.test(value)) return setError("Use letters, digits, - and _, starting with a letter or _."); - if (taken(value)) return setError(`${value}.py already exists.`); + if (!NAME.test(value)) return setError(t("Use letters, digits, - and _, starting with a letter or _.")); + if (taken(value)) return setError(t("{{name}}.py already exists.", { name: value })); setBusy(true); setError(null); try { await onCreate(value, kind); onDone(); } catch (reason) { - setError(reason instanceof Error ? reason.message : "Could not create the notebook."); + setError(reason instanceof Error ? reason.message : t("Could not create the notebook.")); } finally { setBusy(false); } @@ -197,7 +198,7 @@ function NewEntry({ void submit(); }} > - {first &&

An empty workspace. Start with a part: a notebook that builds one solid.

} + {first &&

{t("An empty workspace. Start with a part: a notebook that builds one solid.")}

} event.key === "Escape" && !first && onCancel()} - placeholder="name, e.g. bracket" - aria-label="Name of the new notebook" + placeholder={t("name, e.g. bracket")} + aria-label={t("Name of the new notebook")} spellCheck={false} className="w-full border-2 border-input bg-transparent px-2 py-1 focus:border-focus focus:outline-none" /> @@ -218,7 +219,7 @@ function NewEntry({ key={option} type="button" disabled={option === "assembly" && parts.length === 0} - title={option === "assembly" && parts.length === 0 ? "An assembly puts parts together: create a part first" : undefined} + title={option === "assembly" && parts.length === 0 ? t("An assembly puts parts together: create a part first") : undefined} onClick={() => { setKind(option); input.current?.focus(); // Enter then creates @@ -228,23 +229,23 @@ function NewEntry({ kind === option ? "border-primary bg-primary text-primary-foreground" : "border-transparent text-muted-foreground hover:border-input hover:text-foreground", )} > - {option} + {t(option)} ))}
{kind === "assembly" && parts.length > 0 && (

- Starts with {parts.slice(0, 2).map((row) => row.name).join(" and ")}; change what it uses in its cells. + {t("Starts with {{parts}}; change what it uses in its cells.", { parts: parts.slice(0, 2).map((row) => row.name).join(", ") })}

)} {error &&

{error}

}
{!first && ( )}
diff --git a/editor-web/src/components/OperationChooser.tsx b/editor-web/src/components/OperationChooser.tsx index 533750c3..58d11f8a 100644 --- a/editor-web/src/components/OperationChooser.tsx +++ b/editor-web/src/components/OperationChooser.tsx @@ -3,6 +3,7 @@ import { useRef } from "react"; import { cn } from "@/lib/utils"; import { isEnabled, moveIndex, type SegmentOption } from "@/lib/segmented"; +import { t } from "@/i18n"; /** A segmented control: one of a few short choices, always visible (a radio group, not a dropdown). * @@ -71,7 +72,7 @@ export function OperationChooser({ aria-checked={on} disabled={Boolean(option.disabled)} tabIndex={index === tabbable ? 0 : -1} - title={reason ?? option.hint} + title={reason ? t(reason) : option.hint && t(option.hint)} data-testid={`${testId}-${option.value}`} className={cn( "flex flex-1 items-center justify-center gap-1 px-2 py-1 text-[11px] font-semibold uppercase tracking-[0.08em] transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring disabled:cursor-not-allowed disabled:opacity-40", @@ -82,14 +83,14 @@ export function OperationChooser({ onKeyDown={(event) => onKeyDown(event, index)} > {Icon && } - {option.label} + {t(option.label)} ); })}
{(note || hint) && ( - {note ?? `${options[selected]?.label ?? ""} ${hint}.`} + {note ? t(note) : `${t(options[selected]?.label ?? "")} ${hint ? t(hint) : ""}.`} )}
diff --git a/editor-web/src/components/PartialModel.tsx b/editor-web/src/components/PartialModel.tsx index 75ed806a..f618e763 100644 --- a/editor-web/src/components/PartialModel.tsx +++ b/editor-web/src/components/PartialModel.tsx @@ -2,6 +2,7 @@ import { useMemo } from "react"; import { TriangleAlert } from "lucide-react"; import { describePartial, type PartialModel } from "@/lib/partial"; +import { t } from "@/i18n"; /** Says that the model in the viewport is the one before a failing step (a cell failed, so the product was not made): which * step failed and why, and that the steps after it did not run. It stays while the model is partial and goes when the @@ -22,7 +23,7 @@ export function PartialNotice({ partial, titles, docked = false }: { partial: Pa {title} {reason} - {after ? `${after}; the` : "The"} whole model comes back once it is fixed. + {after ? `${after}; ` : ""}{t("the whole model comes back once it is fixed.")} ); } diff --git a/editor-web/src/components/TagSplits.tsx b/editor-web/src/components/TagSplits.tsx index d43a2491..84678cf1 100644 --- a/editor-web/src/components/TagSplits.tsx +++ b/editor-web/src/components/TagSplits.tsx @@ -2,6 +2,7 @@ import { useEffect, useMemo, useState } from "react"; import { Scissors } from "lucide-react"; import type { SceneView } from "@/scene/scene-view"; +import { t } from "@/i18n"; /** A tagged entity an operation split (the server's `tag_splits`, from `scad.list_tag_splits`): the pieces carry * `.split`, and `pieces` lists the scene entities of each. */ @@ -50,13 +51,13 @@ export function TagSplits({ view, splits, sceneVersion, docked = false }: { view
- {splits.length === 1 ? "A tagged entity was split" : `${splits.length} tagged entities were split`} + {splits.length === 1 ? t("A tagged entity was split") : t("{{count}} tagged entities were split", { count: splits.length })}
{splits.map((row) => (
- {row.op} split {row.tag} into {row.into.length}; the tag names none of them: + {t("{{op}} split {{tag}} into {{count}}; the tag names none of them:", { op: row.op, tag: row.tag, count: row.into.length })} {row.into.map((name, index) => ( @@ -71,10 +72,10 @@ export function TagSplits({ view, splits, sceneVersion, docked = false }: { view
diff --git a/editor-web/src/components/WorkplanePlacer.tsx b/editor-web/src/components/WorkplanePlacer.tsx index 3d6e8606..f12d7f3e 100644 --- a/editor-web/src/components/WorkplanePlacer.tsx +++ b/editor-web/src/components/WorkplanePlacer.tsx @@ -8,6 +8,7 @@ import { placeValues, placedFrame, type PlaceFrame, type PlaceValues } from "@/l import { OVERLAY_LAYER } from "@/scene/renderer/brep-renderer"; import type { SceneView } from "@/scene/scene-view"; import type { Vec3 } from "@/lib/sketch-plane"; +import { t } from "@/i18n"; export type PlaceMode = "translate" | "rotate"; @@ -212,16 +213,16 @@ export function WorkplanePlacePanel({ return (
- {title} + {t(title)} onName(event.target.value)} /> - on - onBase(event.target.value)}> {bases.map((item) => (
{fields.map((field) => (