feat(i18n): U3 国际化 — react-i18next 双语框架 + 侧边栏/Header/Login 全量翻译 + 语言切换器
- 安装 i18next + react-i18next,创建 src/i18n/ 配置实例
- 创建 zh-CN.json (120+ 键) + en-US.json 全量英文翻译
- 侧边栏 42+ 菜单项全量 labelKey 国际化
- Header 通知/主题/用户菜单全量翻译
- Login 页面表单/按钮/主题+语言切换器
- zustand useLanguageStore 持久化语言选择
- HTML lang 属性自动同步
- tsc -b=0, npm build=✅, 17/17 测试通过
This commit is contained in:
1 parent
084a3be2cf
commit
2e179ef7f4
15 files changed
+860
-112
No files matched your search
+67
@@ -722,3 +722,70 @@ python3 tests/integration_test.py --host 127.0.0.1 --port 8080 | tail -3
|
||||
- [x] U6: 仅 linux-amd64 agent 二进制(arm64/darwin 通过下载 API)
|
||||
- [x] U7: UpgradeTools 自动升级 git/docker-cli preinstall→lazy
|
||||
- [x] U8: 17/17 集成回归测试通过
|
||||
|
||||
---
|
||||
|
||||
## P3-U3: 国际化 (i18n)
|
||||
|
||||
### 验证用例
|
||||
|
||||
```bash
|
||||
# U1: i18n 依赖已安装
|
||||
cd /srv/aiops/frontend && node -e "
|
||||
const pkg = require('./package.json');
|
||||
const i18n = pkg.dependencies['i18next'];
|
||||
const react = pkg.dependencies['react-i18next'];
|
||||
if (i18n && react) { console.log('✅ i18next:', i18n, 'react-i18next:', react); process.exit(0); }
|
||||
else { console.log('❌ 缺少 i18n 依赖'); process.exit(1); }
|
||||
"
|
||||
|
||||
# U2: 翻译文件存在且键数量合理
|
||||
python3 -c "
|
||||
import json
|
||||
zh = json.load(open('src/locales/zh-CN.json'))
|
||||
en = json.load(open('src/locales/en-US.json'))
|
||||
zh_keys = sum(len(v) for v in zh.values())
|
||||
en_keys = sum(len(v) for v in en.values())
|
||||
assert zh_keys > 100, f'zh-CN keys too few: {zh_keys}'
|
||||
assert en_keys > 100, f'en-US keys too few: {en_keys}'
|
||||
assert zh_keys == en_keys, f'key count mismatch: zh={zh_keys} en={en_keys}'
|
||||
print(f'✅ zh-CN: {zh_keys} keys, en-US: {en_keys} keys')
|
||||
"
|
||||
|
||||
# U3: i18n 配置文件存在
|
||||
test -f src/i18n/index.ts && echo "✅ i18n config exists" || echo "❌ missing i18n config"
|
||||
|
||||
# U4: Sidebar 使用 labelKey
|
||||
grep -c 'labelKey' src/components/layout/Sidebar.tsx | xargs -I{} sh -c '[ {} -gt 40 ] && echo "✅ Sidebar labelKey: {} items" || echo "❌ Sidebar not migrated"'
|
||||
|
||||
# U5: Header 有语言切换器
|
||||
grep -q 'LanguageSwitcher\|Languages' src/components/layout/Header.tsx && echo "✅ Header has language switcher" || echo "❌ no language switcher"
|
||||
|
||||
# U6: Login 页面有 i18n
|
||||
grep -q 'useTranslation\|t(' src/components/auth/Login.tsx && echo "✅ Login i18n" || echo "❌ Login not migrated"
|
||||
|
||||
# U7: tsc -b 零错误
|
||||
npx tsc -b 2>&1 | grep -c 'error TS' | xargs -I{} sh -c '[ {} -eq 0 ] && echo "✅ tsc -b zero errors" || echo "❌ {} errors"'
|
||||
|
||||
# U8: npm run build
|
||||
npm run build 2>&1 | grep -q 'built in' && echo "✅ build success" || echo "❌ build failed"
|
||||
|
||||
# U9: 集成回归
|
||||
python3 tests/integration_test.py --host 127.0.0.1 --port 8080 | tail -3
|
||||
# 期望: 17/17 passed
|
||||
|
||||
# U10: 前端 HTML lang 属性
|
||||
curl -s http://127.0.0.1:8080/ | grep -q 'lang="zh-CN"' && echo "✅ html lang=zh-CN" || echo "❌ lang attribute missing"
|
||||
```
|
||||
|
||||
### 通过标准
|
||||
- [x] U1: `i18next` + `react-i18next` 已安装
|
||||
- [x] U2: `zh-CN.json` + `en-US.json` 翻译文件键数 > 100 且一致
|
||||
- [x] U3: `src/i18n/index.ts` 配置文件就绪
|
||||
- [x] U4: Sidebar 42+ 菜单项使用 `labelKey` 翻译键
|
||||
- [x] U5: Header 右上角有语言切换器(Languages 图标)
|
||||
- [x] U6: Login 页面使用 `useTranslation` + `t()` 函数
|
||||
- [x] U7: `tsc -b` 零错误
|
||||
- [x] U8: `npm run build` 成功
|
||||
- [x] U9: 17/17 集成回归测试通过
|
||||
- [x] U10: HTML `<html lang="zh-CN">` 属性正确
|
||||
Reference in new issue
Block a user