Repository navigation
Replies: 1 comment
|
Filed a cross-cutting proposal that may change the shape of this: make the UI locale an ordered preference list (e.g. If that lands, requests like this one become mostly "add a dictionary and one config entry". Would value your input on the trade-offs there: #11699 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
把"应用恰好发行两种语言(zh/en)"这一硬编码假设从代码中消除:客户端 locale 层、字典 parity 门禁、文档配对门禁、合并驱动与网站投影全部从同一个可配置的发行语言集合派生;新增一种语言只加字典与一条配置,不再需要改动门禁与类型系统。
验收与细节
现状:两语言假设散落在哪些地方
客户端 locale 层(
packages/client/locale):src/locale-settings.ts:LOCALE_IDS = ['zh', 'en'] as const;LocaleSettingsSchema.preference用z.union([...LOCALE_IDS])。src/client/index.ts:展示列表LOCALES、DOCUMENT_LANGUAGE(<html lang>映射)、FALLBACK_LOCALE = 'en'全部硬编码;register(ns, dicts: Record<LocaleId, LocaleDictOf<N>>)的类型要求"恰好所有发行语言";detectBrowserLocale只在硬编码列表中匹配主子标签。locales.ts全部按{ zh, en }成对注册。scripts/locale-dictionary-parity.spec.ts只做 zh/en 键集对等校验。文档配对层(
docs/+scripts/):scripts/verify-translation-pairing.ts以*.zh.md后缀发现配对;foo.i18n.yaml恰好两个 blob 哈希;语言切换为双向链接;结构签名按 source ↔ zh 两两比对。scripts/translation-pairing-merge.ts与.gitattributes的dsh-translation-pairing合并驱动只组合两哈希三元组。docs/i18n/README.md、translation-rules.md、terminology.md以"成对三文件"(foo.md+foo.zh.md+foo.i18n.yaml)为契约。website/VitePress 按 root(zh)/en 两个 locale 投影。问题
"恰好两种语言"不是内容决策,而是被写进了类型系统、schema、门禁与合并驱动。任何第三种语言(例如土耳其语诸变体,或任何未来语言)都无法只靠"加字典"落地:注册表类型、parity 门禁、配对发现、一致性记录、切换链接、结构签名、合并驱动、网站投影都要先做机制改造。这让多语言成为一次性大工程,而不是可持续演进的增量能力。
目标行为
LocaleId联合类型、settings schema、注册表Record<LocaleId, ...>、回退语言、<html lang>映射、parity 门禁、文档配对发现/记录/切换/签名、合并驱动、网站 locale。验收条件
pnpm run typecheck、pnpm run test:gui、locale-dictionary-parity、doc-sync全部通过,且新语言被 parity 与配对门禁覆盖。<html lang>、navigator主子标签匹配对新语言生效。.i18n.yaml可容纳 N 个哈希;新语言文件被要求成对、结构签名逐侧校验;合并驱动在 N 哈希下仍 fail-closed。用户或模型可见变化
测试证据
locale-dictionary-parity.spec.ts、translation-pairing.spec.ts、translation-pairing-merge.spec.ts与 locale 包测试,覆盖 N 语言场景(缺失一侧、哈希失配、切换不全、合并冲突)。pnpm run doc-sync、pnpm run test:gui、pnpm run website:build跑绿。All reactions