From ceeec602bef618c400f67e8cc3c916c72c6e1748 Mon Sep 17 00:00:00 2001 From: Dnyo666 Date: Mon, 30 Nov 2026 14:27:53 +0800 Subject: [PATCH] feat(i18n,plugin): implement end-to-end i18n & L10n v2 architecture and language pack protocol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Build single-source-of-truth 7-domain locale catalog (`locales/{zh-CN,en-US}/*.json`, 1,100+ keys) and `cmd/i18ngen` generator emitting Go catalogs and eager/lazy-split TypeScript domain modules (`core`/`vm` eager; `wizard`/`settings`/`plugins` lazy) - Add zero-dependency ICU MessageFormat subset (`{var}`, `{n, number}`, CLDR `plural`, `select`), 8-hop cycle-free regional fallback (`zh-HK/zh-MO -> zh-Hant -> zh-TW -> zh-CN`), `auto` OS display-language preference, and `en-XA` pseudo-localization across Go and TypeScript - Introduce `CodedError` supportability with `[E_CODE]` badges, collapsible `[detail]` diagnostics, and automatic SMC OSK / SMBIOS serial / MAC / token redaction - Add Host × Guest macOS dual-terminology annotation (`FormatGuestTerm`) across 6 official Apple guest UI locales and localize Win32 system tray, file pickers, and DPI-adaptive `installguide` overlays with CJK font fallback probing - Upgrade L1–L4 plugin localization to dual-track v2: Track A full language packs (`files`, WOFF2 `fonts`, cross-plugin `pluginOverrides`), Track B plugin-scoped `l10n` bundles (`HasUIMessages` isolation), live `plugin/localeChanged` notifications, `< 2ms` static CLI pack loading, and `reims-go plugin locale init|check` translator toolchain with `zh-TW` and `ja-JP` reference packs - Harden security, WCAG 2.1 AA token contrast, `< 768px` responsive drawer & form layouts, and RTL logical properties; add backend security/locale regression tests and frontend `node --test` static/runtime guard suite in CI # Conflicts: # frontend/src/i18n.ts # internal/cli/cli.go # internal/i18n/i18n.go --- .github/workflows/ci.yml | 3 +- cmd/i18ngen/main.go | 327 +++ docs/architecture.md | 5 +- docs/design-guidelines.md | 6 +- docs/plugin-architecture.md | 9 +- frontend/index.html | 2 +- frontend/package.json | 1 + frontend/scripts/test-i18n.mjs | 235 ++ frontend/src/App.tsx | 75 +- frontend/src/components/AboutPage.tsx | 1 + frontend/src/components/AffinityDialog.tsx | 7 +- frontend/src/components/AppSettingsPage.tsx | 9 +- frontend/src/components/CreateWizard.tsx | 11 +- frontend/src/components/ErrorBoundary.tsx | 59 +- frontend/src/components/HostView.tsx | 10 +- frontend/src/components/InstallersPage.tsx | 2 + frontend/src/components/LogPanel.tsx | 35 +- frontend/src/components/PluginPanelFrame.tsx | 20 +- frontend/src/components/PluginsPage.tsx | 10 +- frontend/src/components/RuntimeOnline.tsx | 1 + frontend/src/components/SchemaForm.tsx | 2 + frontend/src/components/SettingsModal.tsx | 40 +- frontend/src/components/Setup.tsx | 8 +- frontend/src/components/Sidebar.tsx | 3 +- frontend/src/components/VMPage.tsx | 19 +- frontend/src/i18n.ts | 1989 +++-------------- frontend/src/i18n/domains/core.gen.ts | 351 +++ frontend/src/i18n/domains/plugins.gen.ts | 138 ++ frontend/src/i18n/domains/settings.gen.ts | 596 +++++ frontend/src/i18n/domains/vm.gen.ts | 377 ++++ frontend/src/i18n/domains/wizard.gen.ts | 170 ++ frontend/src/i18n/icu.ts | 368 +++ frontend/src/i18n/keys.gen.ts | 797 +++++++ frontend/src/i18n/runtime.ts | 12 + frontend/src/lib/format.ts | 82 +- frontend/src/lib/optimizations.ts | 1 + frontend/src/lib/themeEngine.ts | 105 +- frontend/src/styles/app.css | 261 ++- frontend/src/styles/tokens.css | 51 +- frontend/src/styles/ui-contract.ts | 4 +- frontend/src/types.ts | 14 +- frontend/src/ui/controls.tsx | 1 + frontend/src/ui/settings.tsx | 6 +- frontend/src/ui/toast.tsx | 116 +- frontend/ui-contract.json | 4 + frontend/wailsjs/go/models.ts | 25 +- internal/app/app.go | 147 +- internal/app/appupdate_flow.go | 5 +- internal/app/clone_flow.go | 22 +- internal/app/install_guide.go | 20 +- internal/app/plugins_flow.go | 69 +- internal/app/setup.go | 9 + internal/app/snapshot_flow.go | 25 +- internal/app/ssh_flow.go | 12 +- internal/app/vm_monitor.go | 100 +- internal/cli/cli.go | 136 +- internal/cli/plugin.go | 114 +- internal/cli/plugin_locale_test.go | 56 + internal/cli/start.go | 29 +- internal/config/config.go | 4 +- internal/driver/driver.go | 6 +- internal/driver/reims/reims.go | 4 +- internal/host/fonts_other.go | 13 + internal/host/fonts_windows.go | 106 + internal/host/host_other.go | 7 +- internal/i18n/catalog_gen.go | 1127 ++++++++++ internal/i18n/error.go | 149 ++ internal/i18n/glossary.go | 164 ++ internal/i18n/i18n.go | 595 ++--- internal/i18n/i18n_test.go | 282 ++- internal/i18n/icu.go | 705 ++++++ internal/installguide/appearance_windows.go | 306 ++- internal/installguide/dialog_windows.go | 8 +- internal/installguide/guide.go | 305 ++- internal/installguide/overlay_windows.go | 5 +- internal/installguide/overlay_windows_test.go | 142 +- internal/installguide/picker_windows.go | 19 +- internal/opencore/lang.go | 13 +- internal/plugin/assets.go | 57 +- internal/plugin/broker.go | 20 + internal/plugin/builtin/core.go | 19 +- internal/plugin/kernel_test.go | 2 +- internal/plugin/locale_test.go | 315 +++ internal/plugin/locale_tools.go | 467 ++++ internal/plugin/locale_tools_test.go | 172 ++ internal/plugin/manager.go | 792 ++++++- internal/plugin/package.go | 319 ++- internal/plugin/registry.go | 40 +- internal/plugin/rules.go | 17 +- internal/plugin/sidecar.go | 37 +- .../official.lang.ja-jp/locales/core.json | 25 + .../locales/macos-glossary.json | 14 + .../official.lang.ja-jp/locales/native.json | 29 + .../official.lang.ja-jp/locales/vm.json | 21 + .../testdata/official.lang.ja-jp/plugin.json | 59 + .../official.lang.zh-tw/locales/core.json | 25 + .../locales/macos-glossary.json | 14 + .../official.lang.zh-tw/locales/native.json | 29 + .../official.lang.zh-tw/locales/vm.json | 21 + .../testdata/official.lang.zh-tw/plugin.json | 60 + internal/plugin/theme_css.go | 12 +- internal/plugin/types.go | 118 +- internal/runtime/kinds.go | 16 +- internal/tray/tray.go | 46 +- internal/vmstart/affinity.go | 70 +- internal/vmstart/vmstart.go | 40 +- locales/embed.go | 10 + locales/en-US/core.json | 245 ++ locales/en-US/macos-glossary.json | 50 + locales/en-US/native.json | 911 ++++++++ locales/en-US/plugins.json | 69 + locales/en-US/settings.json | 308 +++ locales/en-US/vm.json | 206 ++ locales/en-US/wizard.json | 85 + locales/zh-CN/core.json | 245 ++ locales/zh-CN/macos-glossary.json | 50 + locales/zh-CN/native.json | 911 ++++++++ locales/zh-CN/plugins.json | 69 + locales/zh-CN/settings.json | 308 +++ locales/zh-CN/vm.json | 206 ++ locales/zh-CN/wizard.json | 85 + pkg/pluginsdk/sdk.go | 133 +- pkg/pluginsdk/sdk_test.go | 111 + 123 files changed, 14965 insertions(+), 2965 deletions(-) create mode 100644 cmd/i18ngen/main.go create mode 100644 frontend/scripts/test-i18n.mjs create mode 100644 frontend/src/i18n/domains/core.gen.ts create mode 100644 frontend/src/i18n/domains/plugins.gen.ts create mode 100644 frontend/src/i18n/domains/settings.gen.ts create mode 100644 frontend/src/i18n/domains/vm.gen.ts create mode 100644 frontend/src/i18n/domains/wizard.gen.ts create mode 100644 frontend/src/i18n/icu.ts create mode 100644 frontend/src/i18n/keys.gen.ts create mode 100644 frontend/src/i18n/runtime.ts create mode 100644 internal/cli/plugin_locale_test.go create mode 100644 internal/host/fonts_other.go create mode 100644 internal/host/fonts_windows.go create mode 100644 internal/i18n/catalog_gen.go create mode 100644 internal/i18n/error.go create mode 100644 internal/i18n/glossary.go create mode 100644 internal/i18n/icu.go create mode 100644 internal/plugin/locale_tools.go create mode 100644 internal/plugin/locale_tools_test.go create mode 100644 internal/plugin/testdata/official.lang.ja-jp/locales/core.json create mode 100644 internal/plugin/testdata/official.lang.ja-jp/locales/macos-glossary.json create mode 100644 internal/plugin/testdata/official.lang.ja-jp/locales/native.json create mode 100644 internal/plugin/testdata/official.lang.ja-jp/locales/vm.json create mode 100644 internal/plugin/testdata/official.lang.ja-jp/plugin.json create mode 100644 internal/plugin/testdata/official.lang.zh-tw/locales/core.json create mode 100644 internal/plugin/testdata/official.lang.zh-tw/locales/macos-glossary.json create mode 100644 internal/plugin/testdata/official.lang.zh-tw/locales/native.json create mode 100644 internal/plugin/testdata/official.lang.zh-tw/locales/vm.json create mode 100644 internal/plugin/testdata/official.lang.zh-tw/plugin.json create mode 100644 locales/embed.go create mode 100644 locales/en-US/core.json create mode 100644 locales/en-US/macos-glossary.json create mode 100644 locales/en-US/native.json create mode 100644 locales/en-US/plugins.json create mode 100644 locales/en-US/settings.json create mode 100644 locales/en-US/vm.json create mode 100644 locales/en-US/wizard.json create mode 100644 locales/zh-CN/core.json create mode 100644 locales/zh-CN/macos-glossary.json create mode 100644 locales/zh-CN/native.json create mode 100644 locales/zh-CN/plugins.json create mode 100644 locales/zh-CN/settings.json create mode 100644 locales/zh-CN/vm.json create mode 100644 locales/zh-CN/wizard.json create mode 100644 pkg/pluginsdk/sdk_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c34bae4..07be562 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,10 +39,11 @@ jobs: & ./scripts/build-release-notes.ps1 -Tag $ver -OutFile $tmp Write-Host "PASS CHANGELOG.md contains valid release notes for $ver ($((Get-Item -LiteralPath $tmp).Length) bytes)" - - name: Frontend build + - name: Frontend test & build shell: pwsh run: | pnpm --dir frontend install --frozen-lockfile + pnpm --dir frontend test pnpm --dir frontend build - name: Debug workspace hygiene check & self-test diff --git a/cmd/i18ngen/main.go b/cmd/i18ngen/main.go new file mode 100644 index 0000000..94bb026 --- /dev/null +++ b/cmd/i18ngen/main.go @@ -0,0 +1,327 @@ +// Command i18ngen compiles and validates the canonical JSON message catalogs +// under locales/{zh-CN,en-US}/*.json, enforcing: +// - 100% key parity between zh-CN and en-US in every domain +// - valid lightweight ICU AST syntax across every entry +// - identical {var} placeholder sets between zh-CN, en-US, and optional $params +// +// Outputs: +// - internal/i18n/catalog_gen.go +// - frontend/src/i18n/keys.gen.ts +// - frontend/src/i18n/domains/{core,vm,wizard,settings,plugins}.gen.ts +package main + +import ( + "bytes" + "encoding/json" + "fmt" + "os" + "path/filepath" + "reflect" + "sort" + "strings" + + "github.com/Nwflower/reims-go/internal/i18n" +) + +var ( + allDomains = []string{"core", "vm", "wizard", "settings", "plugins", "native", "macos-glossary"} + goDomains = []string{"native", "macos-glossary", "core"} + feEagerDomains = []string{"core", "vm"} + feLazyDomains = []string{"wizard", "settings", "plugins"} +) + +type parsedEntry struct { + Message string + Params []string + Comment string + MaxLength int +} + +func main() { + root := "." + if _, err := os.Stat("locales/zh-CN/core.json"); err != nil { + fmt.Fprintf(os.Stderr, "i18ngen: must be run from repository root: %v\n", err) + os.Exit(1) + } + + zhByDomain := make(map[string]map[string]parsedEntry) + enByDomain := make(map[string]map[string]parsedEntry) + keyOwnerDomain := make(map[string]string) + + var validationErrors []string + + for _, dom := range allDomains { + zhPath := filepath.Join(root, "locales", "zh-CN", dom+".json") + enPath := filepath.Join(root, "locales", "en-US", dom+".json") + + zhMap, err := readCatalogFile(zhPath) + if err != nil { + fmt.Fprintf(os.Stderr, "i18ngen: read %s: %v\n", zhPath, err) + os.Exit(1) + } + enMap, err := readCatalogFile(enPath) + if err != nil { + fmt.Fprintf(os.Stderr, "i18ngen: read %s: %v\n", enPath, err) + os.Exit(1) + } + + for k := range zhMap { + if prevDom, exists := keyOwnerDomain[k]; exists { + validationErrors = append(validationErrors, fmt.Sprintf("duplicate key %q across domains %q and %q", k, prevDom, dom)) + } + keyOwnerDomain[k] = dom + if _, ok := enMap[k]; !ok { + validationErrors = append(validationErrors, fmt.Sprintf("[%s] key %q exists in zh-CN but missing in en-US", dom, k)) + } + } + for k := range enMap { + if _, ok := zhMap[k]; !ok { + validationErrors = append(validationErrors, fmt.Sprintf("[%s] key %q exists in en-US but missing in zh-CN", dom, k)) + } + } + + keys := sortedKeys(zhMap) + for _, k := range keys { + ze, ok := zhMap[k] + if !ok { + continue + } + ee, ok := enMap[k] + if !ok { + continue + } + _, zhVars, zErr := i18n.ParseICU(ze.Message) + if zErr != nil { + validationErrors = append(validationErrors, fmt.Sprintf("[%s] zh-CN %q invalid ICU syntax: %v", dom, k, zErr)) + continue + } + _, enVars, eErr := i18n.ParseICU(ee.Message) + if eErr != nil { + validationErrors = append(validationErrors, fmt.Sprintf("[%s] en-US %q invalid ICU syntax: %v", dom, k, eErr)) + continue + } + if !reflect.DeepEqual(zhVars, enVars) { + validationErrors = append(validationErrors, fmt.Sprintf("[%s] placeholder mismatch for %q: zh-CN=%v vs en-US=%v", dom, k, zhVars, enVars)) + } + if len(ze.Params) > 0 { + decl := append([]string(nil), ze.Params...) + sort.Strings(decl) + if !reflect.DeepEqual(decl, zhVars) { + validationErrors = append(validationErrors, fmt.Sprintf("[%s] zh-CN $params %v does not match template vars %v for %q", dom, ze.Params, zhVars, k)) + } + } + if len(ee.Params) > 0 { + decl := append([]string(nil), ee.Params...) + sort.Strings(decl) + if !reflect.DeepEqual(decl, enVars) { + validationErrors = append(validationErrors, fmt.Sprintf("[%s] en-US $params %v does not match template vars %v for %q", dom, ee.Params, enVars, k)) + } + } + } + + zhByDomain[dom] = zhMap + enByDomain[dom] = enMap + } + + if len(validationErrors) > 0 { + for _, msg := range validationErrors { + fmt.Fprintln(os.Stderr, "ERROR:", msg) + } + os.Exit(1) + } + + if err := writeGoCatalog(root, zhByDomain, enByDomain); err != nil { + fmt.Fprintf(os.Stderr, "i18ngen: write Go catalog: %v\n", err) + os.Exit(1) + } + if err := writeFrontendCatalogs(root, zhByDomain, enByDomain); err != nil { + fmt.Fprintf(os.Stderr, "i18ngen: write frontend catalogs: %v\n", err) + os.Exit(1) + } + fmt.Println("i18ngen: OK") +} + +func readCatalogFile(path string) (map[string]parsedEntry, error) { + raw, err := os.ReadFile(path) + if err != nil { + return nil, err + } + var rawMap map[string]json.RawMessage + if err := json.Unmarshal(raw, &rawMap); err != nil { + return nil, err + } + out := make(map[string]parsedEntry, len(rawMap)) + for k, v := range rawMap { + if strings.HasPrefix(k, "$") { + continue + } + var plain string + if err := json.Unmarshal(v, &plain); err == nil { + out[k] = parsedEntry{Message: plain} + continue + } + var meta struct { + Message string `json:"message"` + Params []string `json:"$params"` + Comment string `json:"$comment"` + MaxLength int `json:"$maxLength"` + } + if err := json.Unmarshal(v, &meta); err != nil { + return nil, fmt.Errorf("key %q: %w", k, err) + } + out[k] = parsedEntry{ + Message: meta.Message, + Params: meta.Params, + Comment: meta.Comment, + MaxLength: meta.MaxLength, + } + } + return out, nil +} + +func sortedKeys[V any](m map[string]V) []string { + keys := make([]string, 0, len(m)) + for k := range m { + keys = append(keys, k) + } + sort.Strings(keys) + return keys +} + +func writeGoCatalog(root string, zhByDom, enByDom map[string]map[string]parsedEntry) error { + zhMerged := make(map[string]string) + enMerged := make(map[string]string) + params := make(map[string][]string) + + for _, dom := range goDomains { + for k, e := range zhByDom[dom] { + zhMerged[k] = e.Message + if len(e.Params) > 0 { + params[k] = e.Params + } else if ee := enByDom[dom][k]; len(ee.Params) > 0 { + params[k] = ee.Params + } else { + _, vars, _ := i18n.ParseICU(e.Message) + if len(vars) > 0 { + params[k] = vars + } + } + } + for k, e := range enByDom[dom] { + enMerged[k] = e.Message + } + } + + keys := sortedKeys(zhMerged) + var b bytes.Buffer + b.WriteString("// Code generated by cmd/i18ngen; DO NOT EDIT.\n\npackage i18n\n\n") + b.WriteString("var catalog = map[Locale]map[string]string{\n") + b.WriteString("\tZhCN: {\n") + for _, k := range keys { + fmt.Fprintf(&b, "\t\t%q: %q,\n", k, zhMerged[k]) + } + b.WriteString("\t},\n\tEnUS: {\n") + for _, k := range keys { + fmt.Fprintf(&b, "\t\t%q: %q,\n", k, enMerged[k]) + } + b.WriteString("\t},\n}\n\n") + + paramKeys := sortedKeys(params) + b.WriteString("var paramOrder = map[string][]string{\n") + for _, k := range paramKeys { + p := params[k] + quoted := make([]string, len(p)) + for i, name := range p { + quoted[i] = fmt.Sprintf("%q", name) + } + fmt.Fprintf(&b, "\t%q: {%s},\n", k, strings.Join(quoted, ", ")) + } + b.WriteString("}\n") + + return os.WriteFile(filepath.Join(root, "internal/i18n/catalog_gen.go"), b.Bytes(), 0o644) +} + +func writeFrontendCatalogs(root string, zhByDom, enByDom map[string]map[string]parsedEntry) error { + feDir := filepath.Join(root, "frontend/src/i18n") + domDir := filepath.Join(feDir, "domains") + if err := os.MkdirAll(domDir, 0o755); err != nil { + return err + } + + // Merge macos-glossary into frontend core domain as well so UI components can use official glossary keys. + feDomains := []string{"core", "vm", "wizard", "settings", "plugins"} + var allFEKeys []string + + for _, dom := range feDomains { + zhMap := make(map[string]string) + enMap := make(map[string]string) + for k, v := range zhByDom[dom] { + zhMap[k] = v.Message + } + for k, v := range enByDom[dom] { + enMap[k] = v.Message + } + if dom == "core" { + for k, v := range zhByDom["macos-glossary"] { + zhMap[k] = v.Message + } + for k, v := range enByDom["macos-glossary"] { + enMap[k] = v.Message + } + } + + keys := sortedKeys(zhMap) + allFEKeys = append(allFEKeys, keys...) + + isLazy := false + for _, ld := range feLazyDomains { + if ld == dom { + isLazy = true + break + } + } + + var b bytes.Buffer + b.WriteString("// Code generated by cmd/i18ngen; DO NOT EDIT.\n") + if isLazy { + b.WriteString("import { registerBuiltinDomain } from '../runtime'\n\n") + } else { + b.WriteString("\n") + } + fmt.Fprintf(&b, "export const %sZh: Record = {\n", dom) + for _, k := range keys { + fmt.Fprintf(&b, " %s: %s,\n", tsQuoted(k), tsQuoted(zhMap[k])) + } + b.WriteString("}\n\n") + fmt.Fprintf(&b, "export const %sEn: Record = {\n", dom) + for _, k := range keys { + fmt.Fprintf(&b, " %s: %s,\n", tsQuoted(k), tsQuoted(enMap[k])) + } + b.WriteString("}\n") + if isLazy { + fmt.Fprintf(&b, "\nregisterBuiltinDomain(%sZh, %sEn)\n", dom, dom) + } + + if err := os.WriteFile(filepath.Join(domDir, dom+".gen.ts"), b.Bytes(), 0o644); err != nil { + return err + } + } + + sort.Strings(allFEKeys) + var kb bytes.Buffer + kb.WriteString("// Code generated by cmd/i18ngen; DO NOT EDIT.\n\n") + kb.WriteString("export type I18nKey =\n") + for i, k := range allFEKeys { + sep := "" + if i == len(allFEKeys)-1 { + sep = ";" + } + fmt.Fprintf(&kb, " | %s%s\n", tsQuoted(k), sep) + } + return os.WriteFile(filepath.Join(feDir, "keys.gen.ts"), kb.Bytes(), 0o644) +} + +func tsQuoted(s string) string { + raw, _ := json.Marshal(s) + return string(raw) +} diff --git a/docs/architecture.md b/docs/architecture.md index f7e6f63..682d9b5 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -10,7 +10,7 @@ 2. **包装而非重写引擎**:通过受控子进程调用上游 `reims-ctl`、`reims-util` 与 `qemu-img`,不手写易随上游演进失效的 QEMU 启动参数拼接逻辑。 3. **GUI 与 CLI 单文件同源**:所有业务逻辑下沉在 `internal/`。无参数启动 Wails 桌面窗口,带子命令(`reims-go `)进入命令行模式,供终端、脚本与自动化工具调用。 4. **数据目录隔离**:运行时、下载缓存、虚拟机磁盘、快照与临时文件全部落在用户选定的 `` 下,不污染系统盘。 -5. **原生中英双语**:前后端内置 `zh-CN` / `en-US` 双语字典,自动跟随系统语言并支持运行时切换。 +5. **同构多语言与语言包扩展**:单一事实源分域 JSON 词表(`locales/`)在编译期同时生成 Go 与 TypeScript 类型安全字典,前后端共用轻量 ICU 消息语法与多跳区域回退链;主程序内置 `zh-CN` 与 `en-US`(默认 `auto` 跟随系统并支持热切换),其他语种通过 L1 声明式语言包插件按需扩展并覆盖桌面界面、Win32 原生浮层、系统托盘与命令行。 6. **跨平台开发友好**:所有 Windows 原生 API(WHPX、注册表、处理器拓扑、进程亲和性、系统代理、托盘)严格隔离在 `*_windows.go`,提供 `*_other.go` 桩实现,确保非 Windows 环境也能执行 `go build` 与 `go test ./...`。 --- @@ -66,7 +66,8 @@ flowchart TB | `internal/guesttools` | 本地回环鉴权 HTTP/WebDAV 服务:图文双向剪贴板、共享目录、Windows 盘符只读共享、防休眠开关与 `REIMSTOOLS` 辅助盘生成 | | `internal/opencore` | 改写 OpenCore 镜像中的 `prev-lang:kbd`,实现系统外预设 macOS 语言 | | `internal/netproxy` | 统一 HTTP Transport:优先环境变量代理,回退读取 Windows 系统代理配置 | -| `internal/config`、`internal/i18n` | 应用配置持久化(`reims-go.json`)与 Go 端双语消息/结构化错误码 | +| `locales/`、`cmd/i18ngen` | 单一事实源分域 JSON 词表(含译者上下文 `$comment` 与 Apple macOS 官方多语种词汇表)及编译期前后端字典代码生成器 | +| `internal/config`、`internal/i18n` | 应用配置持久化(`reims-go.json`)、轻量 ICU 格式化引擎、多跳语言回退链与带稳定排障码的结构化错误(`CodedError`) | | `internal/thumb`、`internal/tray`、`internal/version` | 4K 截屏行级缩放预览、Windows 系统托盘常驻、版本信息与新版本检查 | | `frontend/src` | 桌面界面:`components/`(页面与对话框)、`ui/`(Radix 基件封装)、`lib/`(格式化、日志与任务)、`styles/`(设计令牌) | | `patches/` | 上游临时补丁队列与 PR 跟踪,见 [`patches/README.md`](../patches/README.md) | diff --git a/docs/design-guidelines.md b/docs/design-guidelines.md index 84b370c..1e75b1c 100644 --- a/docs/design-guidelines.md +++ b/docs/design-guidelines.md @@ -82,7 +82,7 @@ Reims-Go 的桌面外壳遵循「**macOS 的结构与词表,Windows 的平台 ## 6. 视觉、图标与无障碍基线 - **样式令牌化**:所有颜色、字号、间距(4 px 网格)、圆角与阴影统一引用 [`frontend/src/styles/tokens.css`](../frontend/src/styles/tokens.css) 中的 CSS 变量,禁止在组件内联写死颜色或字号。 -- **字体**:内嵌开源 Inter Variable 作为拉丁字体,并针对 Windows DirectWrite 特性显式映射中文字体字重,避免正文过细或中英混排断层。 +- **字体与区域排印**:内嵌开源 Inter Variable 作为拉丁字体,并通过动态 `` 与 `:lang()` 选择器按区域分离东亚字体栈(简体、繁体、日文、韩文各自优先匹配对应系统 UI 字体,避免 Han Unification 异体字混用);繁体与日文正文采用 `400` 字重与更舒展的行高防止高笔画糊字,开启中西文自动盘古间距;Win32 原生引导浮层按脚本分级探测 GDI 字体并支持卡片宽度自适应与长按钮纵向堆叠。语言包插件可附带沙箱校验的 `.woff2` 字体补齐缺字宿主。 - **按钮层级**:每视图至多 1 个实底主按钮;常用操作用次按钮或图标按钮;破坏性操作仅用红字出现在菜单与确认框。 - **纯图标按钮边界**:仅当图标含义通用(启动、停止、设置、更多、新建、复制、关闭、刷新、日志)且既非主操作也非破坏性操作时才允许纯图标;所有纯图标按钮必须具备悬停 Tooltip(含快捷键)、`aria-label` 与 ≥ 28×28 px 的点击热区。领域专有操作(如「弹出安装盘」「显示 VM 窗口」「重启以应用」)必须保留文字。 - **键盘与缩放**:所有可交互项必须为原生 ` diff --git a/frontend/src/components/HostView.tsx b/frontend/src/components/HostView.tsx index 030ec44..50d780f 100644 --- a/frontend/src/components/HostView.tsx +++ b/frontend/src/components/HostView.tsx @@ -1,5 +1,7 @@ import { Cpu, HardDrive, MemoryStick, Plus, RefreshCw, ShieldCheck, Trash } from 'lucide-react' import React, { useEffect, useState } from 'react' +import '../i18n/domains/settings.gen' +import '../i18n/domains/wizard.gen' import { I18nKey, t } from '../i18n' import { formatBytes, gpuCompatHint, gpuKey, gpuMetaLine, sameGPU } from '../lib/format' import { AppState, Locale, StorageBreakdown, Task } from '../types' @@ -154,7 +156,7 @@ export const HostView: React.FC = ({ state, locale, onRefresh, onNewVM, o
{tr('storageBreakdownTitle')} - {formatBytes(storage.total_bytes)} + {formatBytes(storage.total_bytes, locale)}