Skip to content

[COD-46] 修复凭证、用户与设置页面中文残留 - #96

Merged
RobbsLuo merged 1 commit into
mainfrom
COD-46
Dec 3, 2026
Merged

RobbsLuo merged 1 commit into
mainfrom
COD-46

Conversation

@RobbsLuo

@RobbsLuo RobbsLuo commented Dec 3, 2026

Copy link
Copy Markdown
Owner

改动

复用仓库既有 tr() / trText() 文案字典(不引入 i18n 依赖),把五个页面及其弹窗、抽屉、toast、空态的中文全部接入:

  • 凭证管理:pages/credentials/*(表头/单元格/动作/筛选/组头/抽屉/批量 toast)、9 个凭证弹窗(新增/批量导入/限额/标签/权重/网页 Cookie/账号密码/修改密码/时间线)、PoolOverview、lib/credentialImport.ts(粘贴解析错误)。
  • 用户:ROLE_LABELS / ROLE_OPTIONS 渲染点补 tr。
  • 上游渠道:UpstreamStatusPage 全页(档位、组件明细、事故、概况、空态)。
  • 告警:AlertsPage 全页(表头、级别、推送状态、空态、说明)。
  • 设置:SettingsPage 全页;后端下发的 setting.label/description、task.name/description、分组成员名在前端渲染时过词典(中文是词典 msgid,中文模式逐字不变)。
  • 状态/枚举统一映射表:STATE_LABEL、TASK_REPORT_LABEL、ALERT_RULE_LABEL、USAGE_ERROR_LABEL、UPSTREAM_LEVEL_LABEL、CREDIT_SOURCE_LABEL、PROVIDER_LABEL、侧栏角标全部改为「中文源串 + 渲染点 tr」,组件内不再散落字符串。
  • 格式化随语言:formatDuration/formatAgo/formatNumber/formatCompact/formatTime 与额度日期改用界面语言的 locale,英文界面不再出现「分钟/天」与中文月份。
  • 后端错误提示:沿用 COD-43 已落地的 Accept-Language 本地化 + 前端按码兜底,本轮不直出中文原文。

新增护栏:noHardcodedZh.test.ts 文件清单扩到本轮 24 个文件(源码级扫描,剥掉注释与 tr() 实参后不允许出现 CJK);新增 pagesEnglish.test.tsx 渲染级回归(告警页表头/级别、设置页标签与来源徽标、上游页标题、状态/时长/角标取值)。

验证

cd web && pnpm exec tsc --noEmit && pnpm exec vitest run && pnpm build   # 87 files / 1066 tests 通过
uv run ruff check src tests scripts                                      # No issues found
uv run pytest -q --cov-fail-under=100                                    # 6606 passed,覆盖率 100%

@RobbsLuo

RobbsLuo commented Dec 3, 2026

Copy link
Copy Markdown
Owner Author

结论:门槛通过(pnpm --dir web exec vitest run 87 files / 1066 tests 全绿;新增词典键无缺项,源码级 noHardcodedZh 护栏覆盖本轮 24 个文件),但英文模式仍有中文直出,判 不放行。

问题

  1. web/src/api/display.ts:453-462 alertMessage() 原样返回 alert.message,告警页「说明」列(AlertsPage.tsx:139)直出后端中文:src/tasks/alerting.py:295/306/316/332/348/368/384/405/424 写入的是中文句子且不经 webapp/i18n(grep i18n src/tasks/alerting.py 无命中)。违反分诊已定「后端保留中文原文与错误码,前端按错误码映射英文,禁止直出原文」。修法:在 alertMessage 里按 rule + detail 用 tr 模板重建文案,无 detail 时 trText(message) 并补 PHRASES;补一条英文渲染断言。
  2. web/src/pages/SettingsPage.tsx:233 {task.last_error} 未经 tr/trText(src/tasks/runner.py:545 存的是任务异常原文,可能是中文如 InvalidSetting/签到失败),英文模式会露中文。修法:trText(task.last_error) 或后端按码下发。

是否放行:否。修掉 1(必需)与 2(同类)后可复验放行;其余五页表头/状态/弹窗/toast 与词典、locale 处理未发现问题。

@RobbsLuo

RobbsLuo commented Dec 3, 2026

Copy link
Copy Markdown
Owner Author

结论:不放行(fail)。pnpm --dir web exec vitest run 在 4dd74e2 上通过(89 files / 1088 tests),diff 仅 web/、范围正确;但英文模式仍有两处中文插值直出,违反验收点「切英文后无中文」。

问题(均为插值参数没过 tr,msgid 本身已英化)

  1. web/src/pages/AlertsPage.tsx:78 — tr("最近告警{0}", [data ? \(共 ${total} 条)` : ""]),英文渲染成 Recent alerts(共 3 条)。修法:后缀本身入表,tr("最近告警{0}", [data ? tr("(共 {0} 条)", [total]) : ""]),并在 TEXT_EN 补 "(共 {0} 条)": " ({0} total)";noHardcodedZh` 只剥 tr() 首参,抓不到第二参数组,建议该测试同时断言插值实参无 CJK。
  2. web/src/pages/UpstreamStatusPage.tsx:458 — barLabel || "暂无数据" 未过 tr,sources: [](正是 pagesEnglish.test.tsx:158 的 stub)时英文 aria-label 变成 0 sources: 暂无数据。修法:barLabel || tr("暂无数据");顺带 443 行 barLabel 用全角「,」join,英文读作 Normal 3,Low 1,改 getTrLang() === "en" ? ", " : ","。
  3. 次要(不阻塞本次判断,可一并修):web/src/pages/credentials/actions.tsx:160 trText(\签到未成功(code=…)…`)只把前缀入表,收尾全角「)」与后端result.message仍可能出中文;建议整串走tr/rawText`。

修完后重跑 tsc + vitest + build 再提交复验。合并由内核在放行后执行。

@RobbsLuo

RobbsLuo commented Dec 3, 2026

Copy link
Copy Markdown
Owner Author

结论:pass(放行,合并由内核执行)。

验收:pnpm --dir web exec vitest run → 92 files / 1102 tests 全过;pnpm --dir web exec tsc --noEmit 干净;单跑新用例 AlertsUpstreamI18n.en.test.tsx 2 passed。diff 仅 3 文件(text.ts 去掉重复的「近 7/30 天」+ 补失败趋势文案、statsErrors.ts 错误串走 tr、新增告警/上游概况英文回归)。

走查:脚本扫描 pages/ 全部 .ts/.tsx 的中文字面量(排除注释)——唯一未直接命中的是 UsersPage.tsx:476 placeholder,它已走 tr(),字典 text.ts:431 有对应 EN 值,英文态不会漏中文;其余全部命中现有字典。后端错误提示已由 COD-43(src/webapp/i18n.py 按 Accept-Language)本地化,client.ts 统一带该头,未识别错误走 errorText fallback。

非阻塞 nit:UsersPage.tsx:476 用单引号字面量 tr('例如 {\"daily_requests\": 200, \"rpm\": 5}'),与周边双引号风格不一致,建议下次顺手统一(不影响行为,不阻断放行)。

@RobbsLuo
RobbsLuo merged commit fe4a074 into main Dec 3, 2026
4 of 5 checks passed
@RobbsLuo
RobbsLuo deleted the COD-46 branch December 3, 2026 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant