Skip to content

fix(web): 完善 Files 页面 i18n#607

Open
junxin367 wants to merge 2 commits intotiann:mainfrom
junxin367:fix/files-page-i18n
Open

fix(web): 完善 Files 页面 i18n#607
junxin367 wants to merge 2 commits intotiann:mainfrom
junxin367:fix/files-page-i18n

Conversation

@junxin367
Copy link
Copy Markdown
Contributor

概述

  • 补齐 Files 列表页、文件详情页、目录树未走 i18n 的文案
  • 新增 Files 页面错误文案映射,统一为“中文前缀 + 原始错误详情”
  • 中文下将 detached 显示为“游离 HEAD”,文件详情页 Diff tab 保留为 Diff
  • 删除搜索空态里的不可达英文分支文案

原因

  • Files 页面在中文环境下仍有多处英文直出
  • 查询失败时会直接把英文 fallback / 原始错误暴露给用户

影响范围

  • web/src/routes/sessions/files.tsx
  • web/src/routes/sessions/file.tsx
  • web/src/components/SessionFiles/DirectoryTree.tsx
  • web/src/lib/files-i18n.ts
  • web/src/lib/locales/en.ts
  • web/src/lib/locales/zh-CN.ts

验证

  • bun test web/src/lib/files-i18n.test.ts
  • bun typecheck

风险 / 回滚

  • 风险低;仅影响 Files 相关页面展示文案与错误提示
  • 如需回滚,直接 revert 本 PR 即可

Reviewer Notes

  • 重点看 web/src/lib/files-i18n.ts 的错误映射是否符合预期
  • Diff 在中文下刻意保留英文
  • detached 在中文下改为“游离 HEAD”

截图

  • 无;本次仅文案与错误提示调整,无布局与交互改动

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review mode: initial
1 finding. The Files error formatter can mangle combined staged/unstaged git-status failures; see the inline comment.
Testing: Not run (bun unavailable in runner)

Comment thread web/src/lib/files-i18n.ts Outdated
return t('files.changes.error.gitStatusUnavailable')
}

const unstagedDetail = stripPrefix(detail, 'Unstaged diff unavailable: ')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Minor] This only handles one prefixed failure, but useGitStatusFiles can concatenate both diff errors into a single string (Unstaged ... Staged ...), so the second failure is folded into the translated detail and lost.

Suggested fix:

const segments = detail.split(/(?=Unstaged diff unavailable: |Staged diff unavailable: )/).filter(Boolean)
if (segments.length > 1) {
  return segments.map((segment) => {
    const unstaged = stripPrefix(segment, 'Unstaged diff unavailable: ')\n    if (unstaged) return t('files.changes.error.unstagedDiffUnavailableWithDetail', { error: unstaged })\n    const staged = stripPrefix(segment, 'Staged diff unavailable: ')\n    if (staged) return t('files.changes.error.stagedDiffUnavailableWithDetail', { error: staged })\n    return segment\n  }).join(' ')\n}\n```

Copy link
Copy Markdown
Contributor Author

@junxin367 junxin367 May 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3417f90. formatGitStatusError now splits combined Unstaged ... Staged ... failures into segments and translates each one independently, so both errors are preserved. Added regression coverage in web/src/lib/files-i18n.test.ts.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings
未发现需要阻塞合并的问题。

Summary

  • Review mode: initial
  • 已完整检查本次 Files 页面 i18n diff;剩余风险主要在浏览器端人工验证(语言切换后文件列表、目录树、文件详情页错误态展示)。

Testing

  • Not run (automation: 当前 runner shell 中 bun 不可用,bun test web/src/lib/files-i18n.test.tsbun typecheck 均无法启动)。

HAPI Bot

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