i18n Strategy Analysis¶
重要性:⭐⭐ 目标读者:所有用户(i18n 关注者) 关联:topics/i18n-strategy.md
1. 概览¶
本文档深入分析 Claude Code 的 i18n 策略。
5 主题: - 当前状态 - 字符编码 - 文本方向 - Locale 推断 - UI 文本
2. 当前状态(推测)¶
2.1 已支持¶
- ✅ UTF-8(bashParser 字节偏移)
- ✅ RTL(Yoga Edge 抽象)
- ✅ CJK(measure text)
- ✅ 任何 Unicode 输入
2.2 未支持(推测)¶
- ❌ UI 文本翻译
- ❌ Locale 推断
- ❌ 翻译文件
- ❌ 多语言文档
3. 字符编码详解¶
3.1 bashParser 字节偏移¶
type Lexer = {
byteLen: number
charIdx: number // 字符索引
byteIdx: number // 字节偏移
byteAt(L, charIdx) // 字符 → 字节
}
双索引。
3.2 为什么字节¶
- bash 工具输出用字节
- 与 tree-sitter 兼容
- UTF-8 安全
3.3 3449 黄金语料库¶
大规模验证。
3.4 Ink 字符宽度¶
宽度计算。
4. RTL 支持¶
4.1 Yoga Edge 抽象¶
物理边。
4.2 逻辑边¶
逻辑。
4.3 flexDirection¶
自动 reverse。
4.4 ink/bidi.ts¶
双向文本。
5. Locale 推断¶
5.1 推测实现¶
env 优先。
5.2 Bash Locale¶
UTF-8 默认。
5.3 macOS Locale¶
系统。
5.4 Windows Locale¶
系统。
6. UI 文本(推测英文)¶
6.1 推测英文¶
// settings.json
"description": "Enable debug mode with optional category filtering..."
// 错误信息
throw new Error('Invalid input')
英文。
6.2 推测无 t() 函数¶
未发现。
6.3 推测无 locales/¶
未发现。
7. 4 个 i18n 维度¶
7.1 Locale¶
- ⚠️ 弱
7.2 字符编码¶
- ✅ 强
7.3 文本方向¶
- ✅ 强
7.4 UI 翻译¶
- ❌ 推测无
8. 5 个未来方向¶
8.1 引入 i18next¶
import i18next from 'i18next'
import en from './locales/en.json'
import zh from './locales/zh.json'
i18next.init({ resources: { en, zh } })
i18next。
8.2 翻译文件¶
locales。
8.3 命令 help 翻译¶
help。
8.4 错误码翻译¶
errors。
8.5 文档多语言¶
docs。
9. 5 个最佳实践¶
9.1 用户设置¶
user。
9.2 工具接受 Unicode¶
unicode。
9.3 文件 UTF-8¶
UTF-8。
9.4 终端 i18n¶
locale。
9.5 文档双语¶
双语。
10. 5 个反模式¶
10.1 假设 ASCII¶
ASCII-only。
10.2 不用 byte offset¶
wrong。
10.3 不用 Unicode normalize¶
no-norm。
10.4 不用宽度计算¶
wrong-width。
10.5 UI 硬编码英文¶
hardcode。
11. 5 个 Claude Code 优点¶
11.1 UTF-8 完善¶
bashParser + measure text。
11.2 RTL 完整¶
Yoga Edge 抽象。
11.3 字符宽度¶
CJK 2 倍。
11.4 Unicode 安全¶
3449 黄金语料库。
11.5 接受任意输入¶
不限制字符集。
12. 5 个不足¶
12.1 UI 英文¶
无翻译。
12.2 Locale 推断弱¶
仅 env。
12.3 无翻译文件¶
推测无。
12.4 文档英文¶
无多语言。
12.5 无用户配置¶
无 preferredLanguage。
13. 4 维 trade-off¶
3 维。
14. 关键 insight¶
14.1 i18n 基础设施级¶
UTF-8 + RTL 已实现。
14.2 UI 文本是缺口¶
最缺 i18n 的部分。
14.3 bashParser 完整¶
字节偏移是亮点。
14.4 Yoga RTL 完整¶
支持 6 种 RTL 文本。
14.5 改进空间大¶
i18next 集成即可大幅提升。
15. 总结¶
i18n Strategy = 3 强 1 弱。
核心: - 字符编码强 - RTL 强 - 接受输入强 - UI 翻译弱
下一步: - 引入 i18next - 加 locales - 翻译 help