From 3c8e95e658448f7b6cf8efa8c173644f7fcdf8b4 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Mon, 30 Nov 2026 14:54:29 +0800 Subject: [PATCH] fix(run): show configuration types in the UI language in Add New Configuration The type picker and the Templates list showed each type's English label while the form showed the translation. Rows now carry the translated label, which is also what the list sorts and searches by. --- src/features/run/AddConfigPopup.tsx | 46 +++++++++++++++++------- src/features/run/EditConfigsDialog.tsx | 2 +- src/features/run/runConfigTypes.test.tsx | 14 ++++++++ 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/features/run/AddConfigPopup.tsx b/src/features/run/AddConfigPopup.tsx index fcc2b400b5..d9cf69a5d3 100644 --- a/src/features/run/AddConfigPopup.tsx +++ b/src/features/run/AddConfigPopup.tsx @@ -13,32 +13,48 @@ import { type PopupAnchor, } from "@/ui"; import { useRowHeight } from "@/ui/density"; +import { useTx } from "@/platform/i18n"; import { useRunConfigTypes, runConfigTypes, type RunConfigTypeContribution } from "@/workbench/contributions"; import styles from "./Run.module.css"; export type TypeRow = | { kind: "group"; key: string; label: string } - | { kind: "type"; key: string; type: RunConfigTypeContribution; indices: number[] | null; nested: boolean }; + | { + kind: "type"; + key: string; + type: RunConfigTypeContribution; + /** The type's label in the UI language: what the row shows and the query matches. */ + label: string; + indices: number[] | null; + nested: boolean; + }; const ROW = 24; -/** "Add New Configuration" rows: types by label, grouped ones under their group; filtered by `query`. */ -export function typeRows(types: readonly RunConfigTypeContribution[], query: string): TypeRow[] { +/** + * "Add New Configuration" rows: types by label, grouped ones under their group; filtered by `query`. Labels and groups + * go through `translate` first, so the list is sorted, shown and searched in the UI language. + */ +export function typeRows( + types: readonly RunConfigTypeContribution[], + query: string, + translate: (text: string) => string = (text) => text, +): TypeRow[] { const q = query.trim(); const match = (t: RunConfigTypeContribution) => - q ? (fuzzyMatch(t.label, q) ?? (t.group && fuzzyMatch(t.group, q) ? [] : null)) : null; + q ? (fuzzyMatch(translate(t.label), q) ?? (t.group && fuzzyMatch(translate(t.group), q) ? [] : null)) : null; const rows: TypeRow[] = []; const groups = new Map(); const entries: Array<{ label: string; group?: string; type?: RunConfigTypeContribution }> = []; for (const t of types) { if (!t.group) { - entries.push({ label: t.label, type: t }); + entries.push({ label: translate(t.label), type: t }); continue; } let g = groups.get(t.group); if (!g) { groups.set(t.group, (g = [])); - entries.push({ label: t.group, group: t.group }); + entries.push({ label: translate(t.group), group: t.group }); } g.push(t); } @@ -46,7 +62,8 @@ export function typeRows(types: readonly RunConfigTypeContribution[], query: str for (const e of entries) { if (e.type) { const indices = match(e.type); - if (!q || indices) rows.push({ kind: "type", key: e.type.id, type: e.type, indices, nested: false }); + if (!q || indices) + rows.push({ kind: "type", key: e.type.id, type: e.type, label: e.label, indices, nested: false }); continue; } const members = groups @@ -54,8 +71,9 @@ export function typeRows(types: readonly RunConfigTypeContribution[], query: str .map((t) => ({ t, indices: match(t) })) .filter((x) => !q || x.indices); if (!members.length) continue; - rows.push({ kind: "group", key: `group:${e.group}`, label: e.group! }); - for (const { t, indices } of members) rows.push({ kind: "type", key: t.id, type: t, indices, nested: true }); + rows.push({ kind: "group", key: `group:${e.group}`, label: e.label }); + for (const { t, indices } of members) + rows.push({ kind: "type", key: t.id, type: t, label: translate(t.label), indices, nested: true }); } return rows; } @@ -73,7 +91,8 @@ export function AddConfigPopup({ const types = useRunConfigTypes((s) => s.types); const rowHeight = useRowHeight(ROW); const [query, setQuery] = useState(""); - const rows = useMemo(() => typeRows(runConfigTypes(types), query), [types, query]); + const tx = useTx(); + const rows = useMemo(() => typeRows(runConfigTypes(types), query, tx), [types, query, tx]); const isSection = (r: TypeRow) => r.kind === "group"; const [active, setActive] = useState(-1); const clamped = Math.min(active, rows.length - 1); @@ -149,10 +168,13 @@ export function AddConfigPopup({ } renderItem={(r) => r.kind === "type" ? ( - + - {r.indices?.length ? : r.type.label} + {r.indices?.length ? : r.label} ) : null diff --git a/src/features/run/EditConfigsDialog.tsx b/src/features/run/EditConfigsDialog.tsx index ea9b1d0650..4ebf40efe4 100644 --- a/src/features/run/EditConfigsDialog.tsx +++ b/src/features/run/EditConfigsDialog.tsx @@ -647,7 +647,7 @@ function EditConfigsDialog() { onClick={() => setSelection({ type: "template", kind: t.id })} > - {t.label} + {tx(t.label)} ); })} diff --git a/src/features/run/runConfigTypes.test.tsx b/src/features/run/runConfigTypes.test.tsx index 4b79d065a8..714541fd45 100644 --- a/src/features/run/runConfigTypes.test.tsx +++ b/src/features/run/runConfigTypes.test.tsx @@ -796,6 +796,20 @@ describe("configuration types", () => { expect(typeRows(types, "grad").map((r) => r.key)).toEqual(["gradle"]); expect(typeRows(types, "dock").map((r) => r.key)).toEqual(["group:Docker", "docker-image"]); }); + + it("Add New Configuration shows, sorts and searches types in the UI language", () => { + const zh: Record = { Compound: "复合", "Docker Image": "Docker 镜像", Docker: "Docker 组" }; + const translate = (text: string) => zh[text] ?? text; + const types = [ + ...runConfigTypes(), + { ...BUILTIN_TYPES[0]!, id: "docker-image", label: "Docker Image", group: "Docker" }, + ]; + const rows = typeRows(types, "", translate); + expect(rows.find((r) => r.kind === "type" && r.type.id === "compound")).toMatchObject({ label: "复合" }); + expect(rows.find((r) => r.kind === "group")).toMatchObject({ label: "Docker 组" }); + expect(typeRows(types, "复合", translate).map((r) => r.key)).toEqual(["compound"]); + expect(typeRows(types, "镜像", translate).map((r) => r.key)).toEqual(["group:Docker", "docker-image"]); + }); }); describe("compound configurations", () => {