@huaqiu/dsh-hardware-ui 0.7.18 → 0.7.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,86 +1,117 @@
1
1
  /**
2
- * zh_CN copy for every user-visible string of the Hardware Engineering product
3
- * UI (browser half).
2
+ * User-visible copy for the Hardware Engineering UI, backed by DSH's locale
3
+ * service.
4
4
  *
5
- * Why one module instead of strings at the call sites: the same sentence is
6
- * rendered from up to three seats (navigation row, viewer body, settings
7
- * section), and a literal that drifts between them reads as two different
8
- * products. One dictionary also makes "is this text translated?" a mechanical
9
- * question — grep for a Chinese character outside this file and the answer is
10
- * no.
5
+ * The dictionaries live in {@link ./locales.ts} in the same zh-source/en-checked
6
+ * shape as `@huaqiu/dsh-huaqiu-about` and the other bilingual plugins. `apply`
7
+ * registers them as namespace {@link HARDWARE_UI_NS} and binds a translator;
8
+ * this module keeps the structured call-site API (nested groups, interpolation
9
+ * as functions, string arrays) so nothing that renders needs to change when a
10
+ * language switches. DSH dictionaries are flat `{name}` templates, so the
11
+ * lookup and interpolation happen here, at read time.
11
12
  *
12
- * Why not DSH's own locale service: `ctx.locale.register(ns, { zh, en })` plus a
13
- * `locale: 'ns'` slot registration would put a typed, reactive `t` seat on the
14
- * component props, and it is the right answer for a bilingual plugin. It cannot
15
- * express zh-only: the typed overload takes
16
- * `Record<BuiltInLocaleId, LocaleDictOf<N>>` — both baseline locales are
17
- * required — and the untyped single-locale arm leaves an en-active host falling
18
- * back to the raw key (`FALLBACK_LOCALE = 'en'`, and a namespace registered only
19
- * for `zh` is not in `en`'s chain). The sibling packages hit the same wall and
20
- * self-contained for the same reason (`dsh-auth/src/client/i18n.ts`,
21
- * `dsh-tool-plugin-update/src/client/copy.ts`).
13
+ * Reads are deliberately getters/functions, never captured constants: DSH's
14
+ * renderer re-renders every slot outlet on a locale change, and `bind()` reads
15
+ * the active locale at call time. Before a locale service is bound (unit tests,
16
+ * a Host without one), the context-independent zh dictionary is used — the
17
+ * behaviour this module had when it shipped zh-only.
22
18
  *
23
- * Why one module instead of strings at the call sites: the same sentence is
24
- * rendered from up to three seats (navigation row, viewer body, settings
25
- * section), and a literal that drifts between them reads as two different
26
- * products. One dictionary also makes "is this text translated?" a mechanical
27
- * question — grep for a Chinese character outside this file and the answer is
28
- * no.
29
- *
30
- * Adding a language later is mechanical: turn `COPY` into `{ zh, en }` with
31
- * `en: Record<CopyKeys, string>` (the `dsh-auth` shape, so a missing key is a
32
- * COMPILE error), pick by `<html lang>`, and — if the second language is real —
33
- * move the dictionary into `ctx.locale.register` and declare `locale:` on the
34
- * slots to get the framework's reactive `t` seat instead. Nothing that renders
35
- * would move, because every render site already reads through this module.
36
- *
37
- * Wording rules that hold across the file:
19
+ * Wording rules that hold across both languages:
38
20
  * - Commands, file names, extension names, and host paths are NOT translated
39
- * (`kicad-cli`, `.kicad_pcb`, `Settings → Hardware Engineering` becomes
40
- * 「设置 → 硬件工程」 only because the host section label is translated too).
21
+ * (`kicad-cli`, `.kicad_pcb`, `Settings → Hardware Engineering`).
41
22
  * - Host-origin text is never re-spelled here: {@link describeHostError} maps
42
- * a stable host `code` to a sentence and appends the host detail where it
43
- * is technical output (kicad-cli stderr) rather than prose.
44
- * - Interpolation is a function, not `{placeholder}` templates: a function
45
- * cannot be rendered with its placeholders unfilled by accident.
23
+ * a stable host `code` to a sentence and appends the host detail only where
24
+ * it is technical output (kicad-cli stderr) rather than prose.
25
+ * - Interpolation is a function, not a `{placeholder}` at the call site: a
26
+ * function cannot be rendered with its placeholders unfilled by accident.
27
+ *
28
+ * Adding a language is mechanical: add its dictionary to `locales.ts` (checked
29
+ * against the `zh` key union) and pass it to `locale.register` in `index.ts`.
30
+ * No render site moves.
46
31
  *
47
- * @module
32
+ * @module @huaqiu/dsh-hardware-ui/client/copy
48
33
  */
49
34
 
50
- /** The only locale this bundle ships. See the module note above. */
35
+ import { en, zh, type HardwareCopyKey } from './locales.js'
36
+
37
+ /** DSH locale namespace owned by this plugin. */
38
+ export const HARDWARE_UI_NS = 'hardware-ui.huaqiu'
39
+
40
+ /** Fallback dictionary locale, used only until DSH's locale service is bound. */
51
41
  export const LOCALE = 'zh_CN' as const
52
42
 
43
+ export type TranslateCopy = (key: HardwareCopyKey, params?: Record<string, unknown>) => string
44
+
45
+ /** The slice of DSH's client locale service this module needs. */
46
+ export interface CopyLocale {
47
+ register(namespace: string, dictionaries: { readonly zh: typeof zh; readonly en: typeof en }): unknown
48
+ bind(namespace: string): (key: string, params?: Record<string, unknown>) => string
49
+ }
50
+
51
+ function interpolate(template: string, params?: Record<string, unknown>): string {
52
+ return template.replace(/\{([A-Za-z][\w.-]*)\}/gu, (match, name: string) => {
53
+ const value = params?.[name]
54
+ return value === undefined ? match : String(value)
55
+ })
56
+ }
57
+
58
+ const fallback: TranslateCopy = (key, params) => interpolate(zh[key], params)
59
+ let active: TranslateCopy = fallback
60
+
61
+ /** Read one dictionary entry through the active locale. */
62
+ export function translateCopy(key: HardwareCopyKey, params?: Record<string, unknown>): string {
63
+ return active(key, params)
64
+ }
65
+
66
+ /**
67
+ * Bind the copy facade to DSH's locale service.
68
+ *
69
+ * Call once from the client entry. The returned disposer restores the zh
70
+ * fallback so an HMR reload cannot leave a stale binding behind.
71
+ */
72
+ export function installCopyLocale(locale?: CopyLocale): () => void {
73
+ if (locale === undefined) return () => {}
74
+ const dispose = locale.register(HARDWARE_UI_NS, { zh, en })
75
+ const bound = locale.bind(HARDWARE_UI_NS)
76
+ const installed: TranslateCopy = (key, params) => bound(key, params)
77
+ active = installed
78
+ return () => {
79
+ if (active === installed) active = fallback
80
+ if (typeof dispose === 'function') dispose()
81
+ }
82
+ }
83
+
53
84
  export const COPY = {
54
85
  /** Product name — tab title, settings section label, wizard title. */
55
86
  product: {
56
- name: '硬件工程',
87
+ get name(): string { return translateCopy('product.name') },
57
88
  },
58
89
 
59
90
  /** The five persistent destinations, in `DESTINATIONS` order. */
60
91
  destinations: {
61
- schematic: '原理图',
62
- pcb: 'PCB',
63
- bom: 'BOM',
64
- '3d': '3D 模型',
65
- order: '下单',
92
+ get schematic(): string { return translateCopy('destinations.schematic') },
93
+ get pcb(): string { return translateCopy('destinations.pcb') },
94
+ get bom(): string { return translateCopy('destinations.bom') },
95
+ get '3d'(): string { return translateCopy('destinations.3d') },
96
+ get order(): string { return translateCopy('destinations.order') },
66
97
  },
67
98
 
68
99
  /** Navigation row + viewer strip. */
69
100
  viewer: {
70
- discoveryFailed: (detail: string) => `产物扫描失败:${detail}`,
71
- installationFailed: (detail: string) => `安装检查失败:${detail}`,
72
- noArtifact: '未选择产物',
73
- kicadMissing: '未找到 KiCad',
74
- kicadVersion: (version: string) => `KiCad ${version}`,
75
- openInKicad: '用 KiCad 打开',
76
- openInKicadTitle: (path: string) => `在 KiCad 中打开 ${path}`,
77
- selectArtifactFirst: '请先选择一个产物',
78
- configureKicad: '请在「设置 → 硬件工程」中配置 KiCad',
79
- selectProject: '选择工程…',
101
+ discoveryFailed: (detail: string): string => translateCopy('viewer.discoveryFailed', { detail }),
102
+ installationFailed: (detail: string): string => translateCopy('viewer.installationFailed', { detail }),
103
+ get noArtifact(): string { return translateCopy('viewer.noArtifact') },
104
+ get kicadMissing(): string { return translateCopy('viewer.kicadMissing') },
105
+ kicadVersion: (version: string): string => translateCopy('viewer.kicadVersion', { version }),
106
+ get openInKicad(): string { return translateCopy('viewer.openInKicad') },
107
+ openInKicadTitle: (path: string): string => translateCopy('viewer.openInKicadTitle', { path }),
108
+ get selectArtifactFirst(): string { return translateCopy('viewer.selectArtifactFirst') },
109
+ get configureKicad(): string { return translateCopy('viewer.configureKicad') },
110
+ get selectProject(): string { return translateCopy('viewer.selectProject') },
80
111
  // aria labels / titles (screen-reader text is visible text too)
81
- projectField: '工程',
82
- schematicSheetField: '原理图页',
83
- boardField: '板文件',
112
+ get projectField(): string { return translateCopy('viewer.projectField') },
113
+ get schematicSheetField(): string { return translateCopy('viewer.schematicSheetField') },
114
+ get boardField(): string { return translateCopy('viewer.boardField') },
84
115
  },
85
116
 
86
117
  /**
@@ -91,24 +122,22 @@ export const COPY = {
91
122
  */
92
123
  placeholder: {
93
124
  title: {
94
- schematic: '暂无原理图',
95
- pcb: '暂无 PCB',
96
- bom: '暂无 BOM',
97
- '3d': '暂无 3D 模型',
98
- order: '暂无可下单的板',
125
+ get schematic(): string { return translateCopy('placeholder.title.schematic') },
126
+ get pcb(): string { return translateCopy('placeholder.title.pcb') },
127
+ get bom(): string { return translateCopy('placeholder.title.bom') },
128
+ get '3d'(): string { return translateCopy('placeholder.title.3d') },
129
+ get order(): string { return translateCopy('placeholder.title.order') },
99
130
  },
100
131
  /** One sentence: what the agent can create for this destination. */
101
132
  guide: {
102
- schematic: '可以让智能体在当前工程中创建原理图(.kicad_sch),创建后会直接在这里显示。',
103
- pcb: '可以让智能体创建 PCB 并完成布局(.kicad_pcb),保存后会直接在这里显示。',
104
- bom: 'BOM 由原理图自动生成:让智能体先创建原理图,BOM 会自动更新。',
105
- '3d': '3D 模型由 PCB 生成:让智能体创建 PCB 后,这里会自动出现三维预览。',
106
- order: '制板与贴片都需要 PCB:让智能体创建 PCB 后即可在这里报价下单。',
133
+ get schematic(): string { return translateCopy('placeholder.guide.schematic') },
134
+ get pcb(): string { return translateCopy('placeholder.guide.pcb') },
135
+ get bom(): string { return translateCopy('placeholder.guide.bom') },
136
+ get '3d'(): string { return translateCopy('placeholder.guide.3d') },
137
+ get order(): string { return translateCopy('placeholder.guide.order') },
107
138
  },
108
139
  /** Shown instead of a destination guide when no project was discovered. */
109
- noProject: '可以让智能体在当前工作区创建 KiCad 工程(.kicad_pro),工程出现后这里会自动刷新。',
110
- /** The ask, phrased so the user can paste it into the conversation. */
111
- askAgent: '对智能体说:「为当前工程创建原理图」/「创建 PCB」/「导出 3D 模型」即可。',
140
+ get noProject(): string { return translateCopy('placeholder.noProject') },
112
141
  },
113
142
 
114
143
  /**
@@ -118,172 +147,278 @@ export const COPY = {
118
147
  * two: known codes get translated, unknown ones fall back to the host text.
119
148
  */
120
149
  discovery: {
121
- selectionRequiredCount: (count: number) => `发现 ${count} 个硬件工程,请明确选择一个。`,
122
- selectionRequiredArtifact: '该工程包含多个可选产物,请明确选择一个。',
123
- noProjectSelected: '尚未选择硬件工程。请打开或选择一个硬件工程。',
124
- noSchematic: '该工程没有可用的根原理图。',
125
- noBoard: '该工程没有可用的 .kicad_pcb 板文件。',
126
- noBoardToOrder: '请先选择板文件,再报价或下单制板。',
150
+ selectionRequiredCount: (count: number): string => translateCopy('discovery.selectionRequiredCount', { count }),
151
+ get selectionRequiredArtifact(): string { return translateCopy('discovery.selectionRequiredArtifact') },
152
+ get noProjectSelected(): string { return translateCopy('discovery.noProjectSelected') },
153
+ get noSchematic(): string { return translateCopy('discovery.noSchematic') },
154
+ get noBoard(): string { return translateCopy('discovery.noBoard') },
155
+ get noBoardToOrder(): string { return translateCopy('discovery.noBoardToOrder') },
127
156
  // Host `issue.code` vocabulary.
128
- noProject: (cwd: string) => (cwd === '' ? '未找到 .kicad_pro 工程文件' : `${cwd} 下未找到 .kicad_pro 工程文件`),
129
- missingProject: (path: string) => `工程文件不存在:${path}`,
130
- badManifest: (detail: string) => `配置文件 .hardware-engineering.json 无效:${detail}`,
157
+ noProject: (cwd: string): string => cwd === ''
158
+ ? translateCopy('discovery.noProject')
159
+ : translateCopy('discovery.noProjectIn', { cwd }),
160
+ missingProject: (path: string): string => translateCopy('discovery.missingProject', { path }),
161
+ badManifest: (detail: string): string => translateCopy('discovery.badManifest', { detail }),
131
162
  },
132
163
 
133
164
  /** schematic / pcb / 3d / bom stages. */
134
165
  preview: {
135
- loading: '正在加载已保存的产物…',
136
- kindSchematic: '原理图',
137
- kindBoard: 'PCB',
138
- revision: (revision: string) => `版本 ${revision}`,
139
- ecadHint: '仅预览已保存的文件;文件必须存在且可解析。',
140
- ecadKindMismatch: (expected: string, actual: string) =>
141
- `宿主返回的产物类型(${actual})与预览类型(${expected})不一致。`,
142
- ecadOverlay: '已保存文件 · 滚轮缩放,拖拽平移',
143
- kicadNotConfigured: 'KiCad 尚未配置。',
144
- glbExporting: '正在用 kicad-cli 导出 PCB 的 GLB…',
145
- glbLoading: '正在加载 3D 模型…',
146
- glbCached: '缓存',
147
- glbGenerated: '已生成',
148
- glbOverlay: '拖拽旋转 · 滚轮缩放',
149
- bomHint: 'BOM 行来自 kicad-cli sch export bom。请在「设置 → 硬件工程」中配置 KiCad。',
150
- bomTitle: (lines: number) => `物料清单 · ${String(lines)} 行`,
151
- bomPlacements: (count: number) => `${String(count)} 个元件位`,
152
- bomColumns: ['位号', '数量', '值', '封装', '备注'] as const,
166
+ get loading(): string { return translateCopy('preview.loading') },
167
+ get kindSchematic(): string { return translateCopy('preview.kindSchematic') },
168
+ get kindBoard(): string { return translateCopy('preview.kindBoard') },
169
+ revision: (revision: string): string => translateCopy('preview.revision', { revision }),
170
+ get ecadHint(): string { return translateCopy('preview.ecadHint') },
171
+ ecadKindMismatch: (expected: string, actual: string): string =>
172
+ translateCopy('preview.ecadKindMismatch', { expected, actual }),
173
+ get ecadOverlay(): string { return translateCopy('preview.ecadOverlay') },
174
+ get kicadNotConfigured(): string { return translateCopy('preview.kicadNotConfigured') },
175
+ get glbExporting(): string { return translateCopy('preview.glbExporting') },
176
+ get glbLoading(): string { return translateCopy('preview.glbLoading') },
177
+ get glbCached(): string { return translateCopy('preview.glbCached') },
178
+ get glbGenerated(): string { return translateCopy('preview.glbGenerated') },
179
+ get glbOverlay(): string { return translateCopy('preview.glbOverlay') },
180
+ get bomHint(): string { return translateCopy('preview.bomHint') },
181
+ bomTitle: (lines: number): string => translateCopy('preview.bomTitle', { lines }),
182
+ bomPlacements: (count: number): string => translateCopy('preview.bomPlacements', { count }),
183
+ get bomColumns(): readonly string[] {
184
+ return [
185
+ translateCopy('preview.bomColumn.reference'),
186
+ translateCopy('preview.bomColumn.quantity'),
187
+ translateCopy('preview.bomColumn.value'),
188
+ translateCopy('preview.bomColumn.footprint'),
189
+ translateCopy('preview.bomColumn.notes'),
190
+ ]
191
+ },
153
192
  },
154
193
 
155
194
  /** Order Placing destination. */
156
195
  order: {
157
- title: '制板与贴片',
158
- packaging: '打包中…',
159
- packageReady: '打包完成',
160
- packagePending: '尚未打包',
161
- packageRunning: '正在运行 kicad-cli 导出 Gerber 与钻孔…',
162
- packageNotPrepared: '尚未打包。',
163
- packageCard: '制板文件包',
164
- packageFiles: (files: number, size: string) => `${String(files)} 个文件 · ${size}`,
165
-
166
- pcbTitle: '裸板制板',
167
- pcbSubtitle: '通过华秋制板服务对选中的板文件报价并下单。',
168
- pcbSummary: (zip: string, files: number, size: string) =>
169
- `${zip} · ${String(files)} 个 Gerber/钻孔文件 · ${size}`,
170
- pcbAction: '提交 PCB 订单',
171
-
172
- smtTitle: '整包贴片',
173
- smtSubtitle: '需要工程根原理图以生成 BOM 与元件坐标。',
174
- smtSummary: (placements: number, lines: number, size: string) =>
175
- `${String(placements)} 个贴片点位 · ${String(lines)} 行 BOM · ${size}`,
176
- smtAction: '提交贴片订单',
177
-
178
- boardFile: '板文件',
179
- placements: '贴片点位',
180
- bomLines: 'BOM 行数',
181
- credential: '登录凭据',
182
- signedIn: '华秋登录',
183
- signedOut: '未登录',
184
-
185
- signInToOrder: '请先登录华秋账号再下单——订单页将以你的账号打开。',
186
- signInToOrderSmt: '请先登录华秋账号再下单贴片——订单页将以你的账号打开。',
187
- waitingForPackage: '正在等待制板文件包。',
188
- configureToPackage: '请配置 KiCad 以打包板文件。',
189
- selectRootSchematic: '请选择根原理图,以便生成 BOM 与坐标。',
196
+ get title(): string { return translateCopy('order.title') },
197
+ get packaging(): string { return translateCopy('order.packaging') },
198
+ get packageReady(): string { return translateCopy('order.packageReady') },
199
+ get packagePending(): string { return translateCopy('order.packagePending') },
200
+ get packageRunning(): string { return translateCopy('order.packageRunning') },
201
+ get packageNotPrepared(): string { return translateCopy('order.packageNotPrepared') },
202
+ get packageCard(): string { return translateCopy('order.packageCard') },
203
+ packageFiles: (files: number, size: string): string => translateCopy('order.packageFiles', { files, size }),
204
+
205
+ get pcbTitle(): string { return translateCopy('order.pcbTitle') },
206
+ get pcbSubtitle(): string { return translateCopy('order.pcbSubtitle') },
207
+ pcbSummary: (zip: string, files: number, size: string): string =>
208
+ translateCopy('order.pcbSummary', { zip, files, size }),
209
+ get pcbAction(): string { return translateCopy('order.pcbAction') },
210
+
211
+ get smtTitle(): string { return translateCopy('order.smtTitle') },
212
+ get smtSubtitle(): string { return translateCopy('order.smtSubtitle') },
213
+ smtSummary: (placements: number, lines: number, size: string): string =>
214
+ translateCopy('order.smtSummary', { placements, lines, size }),
215
+ get smtAction(): string { return translateCopy('order.smtAction') },
216
+ /** Kind name interpolated into the result sentences (not a standalone label). */
217
+ get smtShort(): string { return translateCopy('order.smtShort') },
218
+
219
+ get boardFile(): string { return translateCopy('order.boardFile') },
220
+ get placements(): string { return translateCopy('order.placements') },
221
+ get bomLines(): string { return translateCopy('order.bomLines') },
222
+ get credential(): string { return translateCopy('order.credential') },
223
+ get signedIn(): string { return translateCopy('order.signedIn') },
224
+ get signedOut(): string { return translateCopy('order.signedOut') },
225
+
226
+ get signInToOrder(): string { return translateCopy('order.signInToOrder') },
227
+ get signInToOrderSmt(): string { return translateCopy('order.signInToOrderSmt') },
228
+ get waitingForPackage(): string { return translateCopy('order.waitingForPackage') },
229
+ get configureToPackage(): string { return translateCopy('order.configureToPackage') },
230
+ get selectRootSchematic(): string { return translateCopy('order.selectRootSchematic') },
190
231
 
191
232
  // Board facts (values keep their units, which are not prose).
192
- layers: '层数',
193
- layersValue: (layers: number) => `${String(layers)} 层`,
194
- outline: '外形尺寸',
195
- thickness: '板厚',
196
- minTrace: '最小线宽',
197
- minDrill: '最小钻孔',
198
- outerCopper: '外层铜厚',
199
- defaultValue: '默认',
200
- copperValue: (oz: number | string) => `${String(oz)} oz`,
201
-
202
- agentEntryPoints: 'Agent 入口',
203
- submitting: '提交中…',
204
-
205
- resultTitlePcb: 'PCB 订单已创建',
206
- resultTitleSmt: '贴片订单已创建',
207
- resultLaunched: '已在浏览器打开',
208
- resultReady: '待打开',
209
- resultNote: '与 KiCad 在下单窗口中展示的是同一个页面,已在你的默认浏览器中打开。',
210
- resultLaunchedMessage: (kind: string) => `已在默认浏览器中打开「${kind}」订单页。`,
211
- resultReadyMessage: (kind: string) => `「${kind}」订单页已就绪,打开链接即可继续。`,
212
- openInBrowser: '在浏览器打开',
213
- opening: '正在打开…',
214
- copyUrl: '复制链接',
215
- copied: '已复制',
216
-
217
- confirmAria: '确认下单上传',
218
- confirmTitlePcb: '上传板文件并创建 PCB 订单?',
219
- confirmTitleSmt: '上传贴片文件包?',
220
- confirmBody: '以下文件将发送到华秋下单服务。订单在那里创建,其页面会在你的默认浏览器中打开;付款仍在该页面完成。',
221
- confirmZip: (zip: string, size: string) => `${zip} — Gerber 与钻孔文件(${size})`,
222
- confirmPositions: (size: string) => `元件坐标(${size})`,
223
- confirmBom: (size: string) => `贴片 BOM(${size})`,
224
- confirmHost: (baseUrl: string | undefined) => baseUrl ?? '已配置的下单服务',
225
- confirmAck: '我了解这些板文件将离开本机。',
226
- cancel: '取消',
227
- uploadAndOpen: '上传并打开订单页',
228
- uploading: '正在上传…',
229
-
230
- batch: '生产数量',
231
- batchUnits: (count: number) => `${String(count)} 片`,
232
- quoteBasis: (count: number) => `报价基准 · ${String(count)} 片`,
233
+ get layers(): string { return translateCopy('order.layers') },
234
+ layersValue: (layers: number): string => translateCopy('order.layersValue', { layers }),
235
+ get outline(): string { return translateCopy('order.outline') },
236
+ get thickness(): string { return translateCopy('order.thickness') },
237
+ get minTrace(): string { return translateCopy('order.minTrace') },
238
+ get minDrill(): string { return translateCopy('order.minDrill') },
239
+ get outerCopper(): string { return translateCopy('order.outerCopper') },
240
+ get defaultValue(): string { return translateCopy('order.defaultValue') },
241
+ copperValue: (oz: number | string): string => translateCopy('order.copperValue', { oz }),
242
+
243
+ get agentEntryPoints(): string { return translateCopy('order.agentEntryPoints') },
244
+ get submitting(): string { return translateCopy('order.submitting') },
245
+
246
+ get tabTitle(): string { return translateCopy('order.tabTitle') },
247
+ tabOrder: (id: string): string => translateCopy('order.tabOrder', { id }),
248
+ get tabMissing(): string { return translateCopy('order.tabMissing') },
249
+ get tabAddressHint(): string { return translateCopy('order.tabAddressHint') },
250
+ get openInSystemBrowser(): string { return translateCopy('order.openInSystemBrowser') },
251
+
252
+ get resultTitlePcb(): string { return translateCopy('order.resultTitlePcb') },
253
+ get resultTitleSmt(): string { return translateCopy('order.resultTitleSmt') },
254
+ get resultLaunched(): string { return translateCopy('order.resultLaunched') },
255
+ get resultReady(): string { return translateCopy('order.resultReady') },
256
+ get resultNote(): string { return translateCopy('order.resultNote') },
257
+ resultLaunchedMessage: (kind: string): string => translateCopy('order.resultLaunchedMessage', { kind }),
258
+ resultReadyMessage: (kind: string): string => translateCopy('order.resultReadyMessage', { kind }),
259
+ get openInBrowser(): string { return translateCopy('order.openInBrowser') },
260
+ get opening(): string { return translateCopy('order.opening') },
261
+ get copyUrl(): string { return translateCopy('order.copyUrl') },
262
+ get copied(): string { return translateCopy('order.copied') },
263
+
264
+ get confirmAria(): string { return translateCopy('order.confirmAria') },
265
+ get confirmTitlePcb(): string { return translateCopy('order.confirmTitlePcb') },
266
+ get confirmTitleSmt(): string { return translateCopy('order.confirmTitleSmt') },
267
+ get confirmBody(): string { return translateCopy('order.confirmBody') },
268
+ confirmZip: (zip: string, size: string): string => translateCopy('order.confirmZip', { zip, size }),
269
+ confirmPositions: (size: string): string => translateCopy('order.confirmPositions', { size }),
270
+ confirmBom: (size: string): string => translateCopy('order.confirmBom', { size }),
271
+ confirmHost: (baseUrl: string | undefined): string =>
272
+ baseUrl ?? translateCopy('order.confirmHostFallback'),
273
+ get confirmAck(): string { return translateCopy('order.confirmAck') },
274
+ get cancel(): string { return translateCopy('order.cancel') },
275
+ get uploadAndOpen(): string { return translateCopy('order.uploadAndOpen') },
276
+ get uploading(): string { return translateCopy('order.uploading') },
277
+
278
+ get batch(): string { return translateCopy('order.batch') },
279
+ batchUnits: (count: number): string => translateCopy('order.batchUnits', { count }),
280
+ quoteBasis: (count: number): string => translateCopy('order.quoteBasis', { count }),
233
281
  },
234
282
 
235
- /** First-run setup wizard. */
283
+ /**
284
+ * First-run wizard, following `docs/prototype/huaqiu_eda_hardware_toolchain_ux_prototype.html`.
285
+ *
286
+ * These texts are the prototype's own, so a reviewer can diff the running
287
+ * modal against the design instead of translating in their head.
288
+ */
236
289
  wizard: {
237
- steps: ['欢迎', 'KiCad', 'SolidCraft'] as const,
238
- stepCounter: (index: number, total: number, label: string) =>
239
- `${String(index)}/${String(total)} · ${label}`,
240
- aria: '硬件工程初始化',
241
-
242
- welcomeTitle: '配置你的硬件工具链',
243
- welcomeKicker: '仅需一次 · 可跳过',
244
- welcomeLead: '硬件工程可预览 KiCad 工程、导出 PCB 三维模型、打包制板文件并调用本地程序打开文件。只需指定一次本地安装位置。',
245
- welcomeUsesTitle: '使用到的组件',
246
- welcomeUses: 'kicad-cli 负责预览、BOM、GLB 与 Gerber/钻孔打包。SolidCraft 仅作为环境上下文提供给 Agent。',
247
- welcomeLocal: '只使用本机的可执行文件。不会上传任何内容,也不会替你安装任何东西。',
248
-
249
- kicadTitle: 'KiCad 安装位置',
250
- kicadOptional: '可选',
251
- kicadLead: '填写 KiCad 安装目录或 kicad-cli 路径。它用于 .kicad_sch / .kicad_pcb 预览、PCB 的 GLB 导出、制板文件打包,以及「用 KiCad 打开」。',
252
- kicadPlaceholder: 'C:\\Program Files\\KiCad\\8.0\\ 或 /usr/bin/kicad-cli',
253
- kicadSkipHint: '留空即跳过。之后可在「设置 → 硬件工程」中配置。',
254
-
255
- solidcraftTitle: 'SolidCraft 安装位置',
256
- solidcraftLead: '本 POC 中 SolidCraft 仅作为环境上下文提供给 Agent——不启动本地程序,也不做结构预览。',
257
- solidcraftPlaceholder: 'C:\\Program Files\\SolidCraft\\bin\\SolidCraft.exe',
258
-
259
- skip: '跳过设置',
260
- back: '上一步',
261
- next: '下一步',
262
- finish: '完成',
263
- saving: '保存中…',
264
- footerNote: '随时可在「设置 → 硬件工程」中修改。',
290
+ get title(): string { return translateCopy('wizard.title') },
291
+ get badge(): string { return translateCopy('wizard.badge') },
292
+ get lead(): string { return translateCopy('wizard.lead') },
293
+ get callout(): string { return translateCopy('wizard.callout') },
294
+ get kicadTitle(): string { return translateCopy('wizard.kicadName') },
295
+ get kicadChip(): string { return translateCopy('wizard.kicadChip') },
296
+ get kicadBlurb(): string { return translateCopy('wizard.kicadBlurb') },
297
+ get kicadPlaceholder(): string { return translateCopy('wizard.kicadPlaceholder') },
298
+ get solidcraftPlaceholder(): string { return translateCopy('wizard.solidcraftPlaceholder') },
299
+ get solidcraftTitle(): string { return translateCopy('wizard.solidcraftName') },
300
+ get solidcraftChip(): string { return translateCopy('wizard.solidcraftChip') },
301
+ get solidcraftBlurb(): string { return translateCopy('wizard.solidcraftBlurb') },
302
+ get selectFile(): string { return translateCopy('wizard.selectFile') },
303
+ /**
304
+ * The prototype's wizard badge once a tool is usable: `✓ Ready (v10.0.7)`.
305
+ * It says "ready", not "configured", because the wizard is about what the user
306
+ * can start using now — a path the Host just validated counts, saved or not.
307
+ */
308
+ ready: (label: string): string => translateCopy('wizard.ready', { label }),
309
+ get readyDetected(): string { return translateCopy('wizard.readyDetected') },
310
+ dontHave: (name: string): string => translateCopy('wizard.dontHave', { name }),
311
+ get serverDownload(): string { return translateCopy('wizard.serverDownload') },
312
+ get footer(): string { return translateCopy('wizard.footer') },
313
+ get skip(): string { return translateCopy('wizard.skipNow') },
314
+ get save(): string { return translateCopy('wizard.save') },
265
315
  },
266
316
 
267
317
  /** Settings section (the two CAD installation roots). */
268
318
  settings: {
269
- title: '硬件工程',
270
- lead: '用于预览、制板打包、一键调用本地程序以及 Agent 环境上下文的本地 EDA / MCAD 可执行文件。',
271
- kicadTitle: 'KiCad EDA 套件',
272
- kicadBlurb: '可填 KiCad 安装目录或 kicad-cli 路径。用于 .kicad_sch / .kicad_pcb 预览、GLB 导出、BOM、Gerber 打包与本地打开。',
273
- kicadPlaceholder: 'C:\\Program Files\\KiCad\\8.0\\ 或 /usr/bin/kicad-cli',
274
- solidcraftTitle: 'SolidCraft 三维 CAD',
275
- solidcraftBlurb: '本 POC 中仅用于 Agent 环境上下文。不启动本地程序,也不做结构预览;「3D 模型」页签渲染的是所选 PCB。',
276
- solidcraftPlaceholder: 'C:\\Program Files\\SolidCraft\\bin\\SolidCraft.exe',
277
- pathField: (title: string) => `${title}路径`,
278
- validate: '校验并保存',
279
- validating: '校验中…',
280
- configured: '已配置',
281
- notConfigured: '未配置',
282
- notDetected: '未检测到',
283
- savedAndValidated: (application: string) => `${application} 校验通过并已保存。`,
284
- savedButInvalid: (application: string, detail: string) => `${application} 已保存,但校验失败:${detail}`,
285
- hostSettingsUnavailable: '宿主未提供设置服务,无法保存。',
286
- hostRejected: (application: string) => `宿主拒绝了${application}的设置。`,
319
+ get title(): string { return translateCopy('settings.title') },
320
+ get lead(): string { return translateCopy('settings.lead') },
321
+ get kicadTitle(): string { return translateCopy('settings.kicadTitle') },
322
+ get kicadBlurb(): string { return translateCopy('settings.kicadCardBlurb') },
323
+ get kicadPlaceholder(): string { return translateCopy('settings.kicadPlaceholder') },
324
+ get solidcraftTitle(): string { return translateCopy('settings.solidcraftTitle') },
325
+ get solidcraftBlurb(): string { return translateCopy('settings.solidcraftCardBlurb') },
326
+ get solidcraftPlaceholder(): string { return translateCopy('settings.solidcraftPlaceholder') },
327
+ pathField: (title: string): string => translateCopy('settings.pathField', { title }),
328
+ get validate(): string { return translateCopy('settings.validate') },
329
+ get validating(): string { return translateCopy('settings.validating') },
330
+ get configured(): string { return translateCopy('settings.configured') },
331
+ get notConfigured(): string { return translateCopy('settings.notConfigured') },
332
+ get notDetected(): string { return translateCopy('settings.notDetected') },
333
+ savedAndValidated: (application: string): string =>
334
+ translateCopy('settings.savedAndValidated', { application }),
335
+ savedButInvalid: (application: string, detail: string): string =>
336
+ translateCopy('settings.savedButInvalid', { application, detail }),
337
+ get hostSettingsUnavailable(): string { return translateCopy('settings.hostSettingsUnavailable') },
338
+ hostRejected: (application: string): string => translateCopy('settings.hostRejected', { application }),
339
+ get statusVerified(): string { return translateCopy('settings.statusVerified') },
340
+ get statusAwaiting(): string { return translateCopy('settings.statusAwaiting') },
341
+ get statusUnsaved(): string { return translateCopy('settings.statusUnsaved') },
342
+ /** The fading success badge that replaces the (no longer printed) path line. */
343
+ statusSavedBadge: (version: string): string => translateCopy('settings.statusSavedBadge', { version }),
344
+ get statusSavedPlain(): string { return translateCopy('settings.statusSavedPlain') },
345
+ download: (tool: 'kicad' | 'solidcraft', version: string): string => (tool === 'kicad'
346
+ ? translateCopy('settings.downloadKicad', { version })
347
+ : translateCopy('settings.downloadSolidCraft', { version })),
348
+ },
349
+
350
+ /**
351
+ * Toolchain capability: discovery lines, status pills, download affordances
352
+ * and the transient notices of §11. Every sentence here is one that only the
353
+ * plugin can say — the Host's own text arrives separately and is passed
354
+ * through {@link describeHostError} where it is technical.
355
+ */
356
+ toolchain: {
357
+ get checking(): string { return translateCopy('toolchain.checking') },
358
+ get kicadMissing(): string { return translateCopy('toolchain.kicadMissing') },
359
+ get solidcraftMissing(): string { return translateCopy('toolchain.solidcraftMissing') },
360
+ get discovering(): string { return translateCopy('toolchain.discovering') },
361
+ get notDetected(): string { return translateCopy('toolchain.notDetected') },
362
+ detected: (path: string, version: string): string => translateCopy('toolchain.detected', { path, version }),
363
+ detectedInvalid: (path: string, detail: string): string =>
364
+ translateCopy('toolchain.detectedInvalid', { path, detail }),
365
+ get browse(): string { return translateCopy('toolchain.browse') },
366
+ download: (name: string, version: string): string => translateCopy('toolchain.download', { name, version }),
367
+ downloadUnavailable: (name: string): string => translateCopy('toolchain.downloadUnavailable', { name }),
368
+ downloadUnavailableWith: (name: string, detail: string): string =>
369
+ translateCopy('toolchain.downloadUnavailableWith', { name, detail }),
370
+ get official(): string { return translateCopy('toolchain.official') },
371
+ get downloading(): string { return translateCopy('toolchain.downloading') },
372
+ get statusNotConfigured(): string { return translateCopy('toolchain.statusNotConfigured') },
373
+ get browseTitle(): string { return translateCopy('toolchain.browseTitle') },
374
+
375
+ // Executable picker (prototype §3): title, breadcrumb link, hint, footer.
376
+ pickerTitle: (name: string): string => translateCopy('toolchain.pickerTitle', { name }),
377
+ get pickerHint(): string { return translateCopy('toolchain.pickerHint') },
378
+ get pickerNative(): string { return translateCopy('toolchain.pickerNative') },
379
+ get pickerNativeWaiting(): string { return translateCopy('toolchain.pickerNativeWaiting') },
380
+ get pickerRoot(): string { return translateCopy('toolchain.pickerRoot') },
381
+ get pickerNoSelection(): string { return translateCopy('toolchain.pickerNoSelection') },
382
+ get pickerOpen(): string { return translateCopy('toolchain.pickerOpen') },
383
+ get pickerCancel(): string { return translateCopy('toolchain.pickerCancel') },
384
+ pickerOrigin: (origin: 'managed' | 'system' | 'user-local'): string => (origin === 'managed'
385
+ ? translateCopy('toolchain.pickerOriginManaged')
386
+ : origin === 'user-local'
387
+ ? translateCopy('toolchain.pickerOriginUserLocal')
388
+ : translateCopy('toolchain.pickerOriginSystem')),
389
+ get pickerValid(): string { return translateCopy('toolchain.pickerValid') },
390
+ get pickerInvalid(): string { return translateCopy('toolchain.pickerInvalid') },
391
+ get cancel(): string { return translateCopy('toolchain.cancel') },
392
+ get retryCheck(): string { return translateCopy('toolchain.retryCheck') },
393
+ get statusUnconfigured(): string { return translateCopy('toolchain.statusUnconfigured') },
394
+ get statusValidating(): string { return translateCopy('toolchain.statusValidating') },
395
+ get statusConfigured(): string { return translateCopy('toolchain.statusConfigured') },
396
+ get statusInvalid(): string { return translateCopy('toolchain.statusInvalid') },
397
+ statusDownloading: (percent: string): string => translateCopy('toolchain.statusDownloading', { percent }),
398
+ get statusExtracting(): string { return translateCopy('toolchain.statusExtracting') },
399
+ get statusDone(): string { return translateCopy('toolchain.statusDone') },
400
+ get statusFailed(): string { return translateCopy('toolchain.statusFailed') },
401
+ toastStarted: (name: string, version: string): string => translateCopy('toolchain.toastStarted', { name, version }),
402
+ toastDownloaded: (name: string, version: string): string =>
403
+ translateCopy('toolchain.toastDownloaded', { name, version }),
404
+ toastExtracting: (name: string): string => translateCopy('toolchain.toastExtracting', { name }),
405
+ toastInstalled: (name: string, version: string): string =>
406
+ translateCopy('toolchain.toastInstalled', { name, version }),
407
+ toastFailed: (name: string, detail: string): string => translateCopy('toolchain.toastFailed', { name, detail }),
408
+ toastChecksum: (name: string): string => translateCopy('toolchain.toastChecksum', { name }),
409
+ toastCancelled: (name: string): string => translateCopy('toolchain.toastCancelled', { name }),
410
+ toastSaved: (name: string, version: string): string => translateCopy('toolchain.toastSaved', { name, version }),
411
+ toastInvalid: (name: string, detail: string): string => translateCopy('toolchain.toastInvalid', { name, detail }),
412
+ get toastSkipped(): string { return translateCopy('toolchain.toastSkipped') },
413
+ browseUnsupported: (detail: string): string => translateCopy('toolchain.browseUnsupported', { detail }),
414
+ get onboardingTitle(): string { return translateCopy('toolchain.onboardingTitle') },
415
+ get onboardingLead(): string { return translateCopy('toolchain.onboardingLead') },
416
+ get onboardingAria(): string { return translateCopy('toolchain.onboardingAria') },
417
+ get skip(): string { return translateCopy('toolchain.skip') },
418
+ get finish(): string { return translateCopy('toolchain.finish') },
419
+ get footNote(): string { return translateCopy('toolchain.footNote') },
420
+ indicator: (summary: string): string => translateCopy('toolchain.indicator', { summary }),
421
+ get pending(): string { return translateCopy('toolchain.pending') },
287
422
  },
288
423
 
289
424
  /**
@@ -293,27 +428,29 @@ export const COPY = {
293
428
  * answer for an unmodelled failure.
294
429
  */
295
430
  errors: {
296
- unauthorized: '没有权限访问该产物:它不在当前会话的工作区授权范围内。',
297
- forbidden: '没有权限执行该操作。',
298
- 'missing-artifact': '该产物不存在。',
299
- 'unsupported-artifact': '不支持该产物类型。',
300
- 'invalid-identity': '产物路径无效。',
301
- 'missing-executable': '已配置的 KiCad 中没有可打开该产物的程序。',
302
- 'not-configured': '尚未配置 KiCad。请在「设置 → 硬件工程」中填写安装位置。',
303
- 'too-large': '产物超过可预览的大小上限。',
304
- 'export-timeout': 'kicad-cli 执行超时。',
305
- 'export-failed': 'kicad-cli 导出失败。',
306
- 'stale-revision': '文件已变化,请刷新后重试。',
307
- 'invalid-request': '请求参数不完整。',
308
- 'invalid-application': '不支持该本地程序。',
309
- 'confirmation-required': '下单需要先在上传确认框中确认。',
310
- 'invalid-order-url': '订单链接无效,已拒绝打开。',
311
- 'order-unreachable': '无法连接下单服务。',
312
- 'order-rejected': '下单服务未能返回可用的订单页。',
313
- 'not-found': '未找到该接口。',
314
- internal: '服务内部错误。',
431
+ get unauthorized(): string { return translateCopy('errors.unauthorized') },
432
+ get forbidden(): string { return translateCopy('errors.forbidden') },
433
+ get 'missing-artifact'(): string { return translateCopy('errors.missing-artifact') },
434
+ get 'unsupported-artifact'(): string { return translateCopy('errors.unsupported-artifact') },
435
+ get 'invalid-identity'(): string { return translateCopy('errors.invalid-identity') },
436
+ get 'missing-executable'(): string { return translateCopy('errors.missing-executable') },
437
+ get 'not-configured'(): string { return translateCopy('errors.not-configured') },
438
+ get 'too-large'(): string { return translateCopy('errors.too-large') },
439
+ get 'export-timeout'(): string { return translateCopy('errors.export-timeout') },
440
+ get 'export-failed'(): string { return translateCopy('errors.export-failed') },
441
+ get 'stale-revision'(): string { return translateCopy('errors.stale-revision') },
442
+ get 'invalid-request'(): string { return translateCopy('errors.invalid-request') },
443
+ get 'invalid-application'(): string { return translateCopy('errors.invalid-application') },
444
+ get 'confirmation-required'(): string { return translateCopy('errors.confirmation-required') },
445
+ get 'invalid-order-url'(): string { return translateCopy('errors.invalid-order-url') },
446
+ get 'order-unreachable'(): string { return translateCopy('errors.order-unreachable') },
447
+ get 'order-rejected'(): string { return translateCopy('errors.order-rejected') },
448
+ get 'not-found'(): string { return translateCopy('errors.not-found') },
449
+ get 'method-not-allowed'(): string { return translateCopy('errors.method-not-allowed') },
450
+ get 'unknown-job'(): string { return translateCopy('errors.unknown-job') },
451
+ get internal(): string { return translateCopy('errors.internal') },
315
452
  },
316
- } as const
453
+ }
317
454
 
318
455
  export type HardwareCopy = typeof COPY
319
456
 
@@ -331,7 +468,7 @@ const KEEPS_DETAIL = new Set([
331
468
  ])
332
469
 
333
470
  /**
334
- * One host error → one zh_CN sentence.
471
+ * One host error → one sentence in the active locale.
335
472
  *
336
473
  * `detail` is the host's own message. Unknown codes keep it untouched, so an
337
474
  * unmodelled failure still says something specific instead of collapsing into
@@ -341,7 +478,9 @@ export function describeHostError(code: string | undefined, detail: string): str
341
478
  if (code === undefined) return detail
342
479
  const sentence = (COPY.errors as Record<string, string | undefined>)[code]
343
480
  if (sentence === undefined) return detail
344
- return KEEPS_DETAIL.has(code) && detail !== '' ? `${sentence}(${detail})` : sentence
481
+ return KEEPS_DETAIL.has(code) && detail !== ''
482
+ ? `${sentence}${translateCopy('error.detail', { detail })}`
483
+ : sentence
345
484
  }
346
485
 
347
486
  /**