i18n-helper
Agent skill fromlaolaoshiren/claude-code-skills-zh
国际化/本地化助手 — 扫描代码中的硬编码文本、生成 i18n 配置、批量翻译
How to install i18n-helper
install i18n-helper
# install the claude-code-skills-zh pack with the skills CLI
npx skills add laolaoshiren/claude-code-skills-zh# or add only this skill to Claude Code: copy the folder
skills/i18n-helper/
# into
~/.claude/skills/i18n-helper/ (all projects)
.claude/skills/i18n-helper/ (one project)
1# 🌍 i18n-helper — 国际化/本地化助手23## 触发条件4当用户要求以下操作时激活此技能:5- 扫描代码中的硬编码中文/英文文本6- 为项目添加国际化支持(i18n)7- 批量提取和翻译语言文件8- 检查翻译完整性(缺失 key 检测)910## 工作流程1112### 1. 项目分析13- 检测项目类型(React/Vue/Angular/Node.js/Python/Java 等)14- 识别已使用的 i18n 框架(react-intl, vue-i18n, i18next, gettext 等)15- 扫描源代码目录结构1617### 2. 硬编码文本扫描18- 在 `.js/.jsx/.ts/.tsx/.vue/.py/.java/.go` 等文件中搜索硬编码字符串19- 排除:变量名、URL、正则表达式、import 路径、日志调试信息20- 标记:用户可见的 UI 文本、错误提示、通知消息2122### 3. 语言文件生成23根据项目框架生成对应格式:24- **JSON** (i18next/react-intl): `{ "key": "value" }`25- **YAML** (vue-i18n): `key: value`26- **PO/POT** (gettext): 标准格式27- **Properties** (Java): `key=value`2829### 4. 代码替换30- 将硬编码文本替换为 i18n 函数调用31- 保持原有格式和变量插值32- 示例:33 ```javascript34 // 替换前35 alert('保存成功');36 // 替换后37 alert(t('alert.saveSuccess'));38 ```3940### 5. 完整性检查41- 对比主语言文件与翻译文件的 key 差异42- 输出缺失翻译的 key 列表43- 统计翻译完成度百分比4445## 输出格式46```markdown47## 📊 i18n 扫描报告4849### 硬编码文本50| 文件 | 行号 | 内容 | 建议 key |51|------|------|------|----------|52| src/App.tsx | 42 | '欢迎使用' | page.welcome |5354### 语言文件55已生成 `locales/zh-CN.json` 和 `locales/en-US.json`5657### 翻译完整性58- zh-CN: 45/45 (100%) ✅59- en-US: 42/45 (93.3%) ⚠️ 缺少 3 个 key60```6162## 支持的 i18n 框架63- react-intl / FormatJS64- vue-i18n65- i18next / react-i18next / next-i18next66- Angular @ngx-translate67- Python gettext / Flask-Babel68- Java ResourceBundle / Spring MessageSource69- Go go-i18n7071## 注意事项72- 不要翻译技术术语(API、SDK、HTTP 等)73- 保留变量占位符 `{name}` `{{count}}` `%s` 等格式74- 复数形式和性别变体需要特殊处理75- 日期、数字、货币格式需使用 locale 感知的格式化函数
Excerpt shown under the repository's MIT license.
