Repository navigation
fix(i18n): 一处键差异被 checkKeyParity 报成两条,且 extra 的 locale 标签指向错误一侧 - #210
Merged
helsome merged 1 commit intoOct 18, 2026
Merged
Conversation
checkKeyParity() 外层遍历全部 locale,内层再对 flat / otherFlat 各比较一次,
导致同一处 en/zh 键差异产出 missing + extra 两条 issue;其中 extra 那条的
locale 填的是当前 locale 而不是缺键的一侧,标签与事实相反。
i18n:check 把 issues.length 直接当作 failures 打印(scripts/i18n-check.ts:57),
所以 CI 日志里的 `i18n:check FAILED — N issue(s)` 与实际差异处数不符:一处差异
报成 2 条。assertKeyParity() 的样本额度(前 8 条)也被重复项占掉一半。
改为以 SUPPORTED_LOCALES_FOR_RESOURCES[0] 为基准 locale 单向比较,并把三类
issue 的 locale 统一为「有问题的那一侧」:missing = 该 locale 缺少基准键,
extra = 该 locale 多出基准没有的键,interpolation-mismatch = 该 locale 的
{{var}} 集合与基准不一致。
验证:
- 新增 3 条回归用例(一处缺失 / 一处多余 / 一处插值不一致)
- 修复前 bun test packages/i18n/src/resources.test.ts --isolate = 5 pass / 3 fail
(三条均为 Expected length: 1 / Received length: 2)
- 修复后同文件 = 8 pass / 0 fail;packages/i18n 全目录 = 28 pass / 0 fail
- 真实脚本对照:删除 zh-CN 的 navigation.today 后,
修复前 bun run i18n:check 输出 [missing zh-CN] + [extra zh-CN]、FAILED — 2 issue(s);
修复后输出 [missing zh-CN]、FAILED — 1 issue(s)
- 键对齐时 bun run i18n:check 0 issues、exit 0;bun run typecheck 五个工作区 exit 0
helsome
approved these changes
Oct 18, 2026
helsome
left a comment
Owner
There was a problem hiding this comment.
本轮独立源码审查及精确 HEAD focused 8/0 通过。最新main累计组合完整测试1959 pass / 7 skip / 0 fail,全workspace typecheck、i18n通过,secret扫描零命中。仅按本PR声明范围验收,不把离线回归当真实模型/生产API验收。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #209
问题
checkKeyParity()外层遍历全部 locale、内层再对flat/otherFlat各比较一次,导致同一处 en/zh键差异产出两条 issue:一条
missing,一条extra;而extra那条的locale填的是当前locale而非缺键的一侧,标签与事实相反。
scripts/i18n-check.ts:56-58把issues.length直接当作failures打印,所以 CI 日志里的i18n:check FAILED — N issue(s)与真实差异处数不符。改动
packages/i18n/src/resources.ts:改为以SUPPORTED_LOCALES_FOR_RESOURCES[0]为基准 locale 单向比较,并把三类 issue 的
locale统一为「有问题的那一侧」:missingextrainterpolation-mismatch{{var}}集合与基准不一致issues.length因此恰好等于差异处数;locale语义在三类之间一致;未来新增第三个 locale 时仍是「以第一个为基准逐个比对」,无需再改结构。
对照证据(真实脚本)
在
packages/i18n/src/locales/zh-CN/navigation.ts中删掉today: '今日',(制造一处差异),bun run i18n:check:修复前(upstream main):
修复后(本 PR):
键对齐时两者一致:
✓ key parity: en-US 1487 keys ≡ zh-CN 1487 keys (0 issues)、exit 0(确认没有把「对齐」误报成问题)。
验证
TDD:先失败后通过
bun test packages/i18n/src/resources.test.ts --isolate三条新用例失败时均为
Expected length: 1 / Received length: 2,分别覆盖:一处缺失键、一处多余键、一处插值不一致。
回归与门禁(本机 Windows / bun 1.x,
--isolate)bun test packages/i18n --isolatebun run i18n:checkbun run typecheckUI
无可见 UI 变化(仅 i18n 校验工具链的报错计数与标签语义;翻译资源本身未改动)。