Trigger Conditions
Activate this skill when the user requests the following operations:
- Scan hardcoded Chinese/English text in code
- Add internationalization support (i18n) to a project
- Batch extract and translate language files
- Check translation completeness (missing key detection)
Workflow
1. Project Analysis
- Detect project type (React/Vue/Angular/Node.js/Python/Java, etc.)
- Identify the i18n framework already in use (react-intl, vue-i18n, i18next, gettext, etc.)
- Scan the source code directory structure
2. Hardcoded Text Scanning
- In
.js/.jsx/.ts/.tsx/.vue/.py/.java/.goand other files, search for hardcoded strings - Exclude: variable names, URLs, regular expressions, import paths, log debug information
- Flag: user-visible UI text, error messages, notification messages
3. Language File Generation
Generate the corresponding format based on the project framework:
- JSON (i18next/react-intl):
{ "key": "value" } - YAML (vue-i18n):
key: value - PO/POT (gettext): standard format
- Properties (Java):
key=value
4. Code Replacement
- Replace hardcoded text with i18n function calls
- Preserve the original formatting and variable interpolation
- Example:
// 替换前 alert('保存成功'); // 替换后 alert(t('alert.saveSuccess'));
5. Completeness Check
- Compare key differences between the primary language file and translation files
- Output the list of keys with missing translations
- Calculate the translation completion percentage
Output Format
## 📊 i18n 扫描报告
### 硬编码文本
| 文件 | 行号 | 内容 | 建议 key |
|------|------|------|----------|
| src/App.tsx | 42 | '欢迎使用' | page.welcome |
### 语言文件
已生成 `locales/zh-CN.json` 和 `locales/en-US.json`
### 翻译完整性
- zh-CN: 45/45 (100%) ✅
- en-US: 42/45 (93.3%) ⚠️ 缺少 3 个 key
Supported i18n Frameworks
- react-intl / FormatJS
- vue-i18n
- i18next / react-i18next / next-i18next
- Angular @ngx-translate
- Python gettext / Flask-Babel
- Java ResourceBundle / Spring MessageSource
- Go go-i18n
Notes
- Do not translate technical terms (API, SDK, HTTP, etc.)
- Preserve variable placeholders
{name}{{count}}%sand other formats - Plural forms and gender variants require special handling
- Date, number, and currency formats must use locale-aware formatting functions