localization
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSoftware Localization Skill
软件本地化Skill
This skill creates high-quality localizations for software projects by using a dual-translation approach with verification.
本技能通过带验证的双重翻译方法,为软件项目创建高质量的本地化内容。
Workflow Overview
工作流程概述
- Detect Project Type - Identify the localization framework and file format
- Validate Target Language - Ensure a valid ISO 639 language code is provided
- Extract Source Strings - Load English (en/en-us/en_us) as the base
- Dual Translation - Two independent translator sub-agents produce translations
- Verification - A third sub-agent compares results and selects the best translations
- Output - Generate the localization file in the correct format
- 检测项目类型 - 识别本地化框架和文件格式
- 验证目标语言 - 确保提供有效的ISO 639语言代码
- 提取源字符串 - 以英文(en/en-us/en_us)作为基准加载
- 双重翻译 - 两个独立的翻译子Agent生成翻译内容
- 验证 - 第三个子Agent对比结果并选择最佳翻译
- 输出 - 生成正确格式的本地化文件
Step 1: Detect Project Type
步骤1:检测项目类型
Before any translation work, identify the localization system by examining the project structure.
在进行任何翻译工作之前,通过检查项目结构识别本地化系统。
Common Patterns to Check
需检查的常见模式
| Framework | Location | Format | Key Pattern |
|---|---|---|---|
| React (react-i18next) | | JSON | |
| React (react-intl) | | JSON | |
| Vue (vue-i18n) | | JSON/YAML | |
| Angular | | JSON/XLIFF | JSON or XML-based |
| iOS | | Strings | |
| Android | | XML | |
| Rails (i18n) | | YAML | |
| Django | | PO/POT | |
| .NET (resx) | | XML | |
| Flutter | | ARB/JSON | |
| Go (go-i18n) | | JSON/TOML | Various |
| PHP (Laravel) | | PHP/JSON | |
| Next.js | | JSON | |
| Gettext | | PO | |
| 框架 | 位置 | 格式 | 键模式 |
|---|---|---|---|
| React (react-i18next) | | JSON | |
| React (react-intl) | | JSON | |
| Vue (vue-i18n) | | JSON/YAML | |
| Angular | | JSON/XLIFF | JSON或基于XML |
| iOS | | Strings | |
| Android | | XML | |
| Rails (i18n) | | YAML | |
| Django | | PO/POT | |
| .NET (resx) | | XML | |
| Flutter | | ARB/JSON | |
| Go (go-i18n) | | JSON/TOML | 多种格式 |
| PHP (Laravel) | | PHP/JSON | |
| Next.js | | JSON | |
| Gettext | | PO | |
Detection Commands
检测命令
bash
undefinedbash
undefinedFind common localization directories
查找常见本地化目录
find . -type d ( -name "locales" -o -name "locale" -o -name "i18n" -o -name "l10n" -o -name "translations" -o -name "lang" -o -name ".lproj" -o -name "values-" ) 2>/dev/null | head -20
find . -type d ( -name "locales" -o -name "locale" -o -name "i18n" -o -name "l10n" -o -name "translations" -o -name "lang" -o -name ".lproj" -o -name "values-" ) 2>/dev/null | head -20
Find localization files
查找本地化文件
find . -type f ( -name ".json" -o -name ".yaml" -o -name ".yml" -o -name ".strings" -o -name ".xml" -o -name ".po" -o -name ".pot" -o -name ".resx" -o -name ".arb" -o -name ".xliff" ) 2>/dev/null | grep -E "(locale|i18n|l10n|lang|translation|messages|values)" | head -30
undefinedfind . -type f ( -name ".json" -o -name ".yaml" -o -name ".yml" -o -name ".strings" -o -name ".xml" -o -name ".po" -o -name ".pot" -o -name ".resx" -o -name ".arb" -o -name ".xliff" ) 2>/dev/null | grep -E "(locale|i18n|l10n|lang|translation|messages|values)" | head -30
undefinedImportant: Examine the English Source
重要提示:检查英文源文件
Once you locate the localization directory, find the English source file. It may be named:
- ,
en.json,en-US.jsonen_US.json - ,
en.yamlen-US.yaml en.lproj/Localizable.strings- (Android default)
values/strings.xml - ,
en.pomessages.pot
Read this file to understand the structure before proceeding.
定位到本地化目录后,找到英文源文件。它可能命名为:
- ,
en.json,en-US.jsonen_US.json - ,
en.yamlen-US.yaml en.lproj/Localizable.strings- (Android默认)
values/strings.xml - ,
en.pomessages.pot
在继续操作前,读取该文件以了解其结构。
Step 2: Validate Target Language
步骤2:验证目标语言
Required Information
必填信息
You MUST have a valid ISO 639 language code before proceeding. If the user provides only a language name, look up the correct code.
在继续操作前,必须提供有效的ISO 639语言代码。如果用户仅提供语言名称,请查找正确的代码。
Clarification Required For
需要澄清的情况
ALWAYS ask for clarification when the user specifies:
- "Chinese" → Ask: Traditional (zh-TW, zh-HK), Simplified (zh-CN, zh-Hans), or another variant?
- "Spanish" → Ask: Spain (es-ES), Latin America (es-419), Mexico (es-MX), or general (es)?
- "Portuguese" → Ask: Brazil (pt-BR) or Portugal (pt-PT)?
- "Serbian" → Ask: Cyrillic (sr-Cyrl) or Latin (sr-Latn)?
- "Norwegian" → Ask: Bokmål (nb) or Nynorsk (nn)?
- "Malay" → Ask: Malaysia (ms-MY), Singapore (ms-SG), or Brunei (ms-BN)?
当用户指定以下内容时,务必询问以澄清:
- “中文” → 询问:繁体(zh-TW、zh-HK)、简体(zh-CN、zh-Hans)还是其他变体?
- “西班牙语” → 询问:西班牙(es-ES)、拉丁美洲(es-419)、墨西哥(es-MX)还是通用西班牙语(es)?
- “葡萄牙语” → 询问:巴西(pt-BR)还是葡萄牙(pt-PT)?
- “塞尔维亚语” → 询问:西里尔文(sr-Cyrl)还是拉丁文(sr-Latn)?
- “挪威语” → 询问:书面挪威语(nb)或新挪威语(nn)?
- “马来语” → 询问:马来西亚(ms-MY)、新加坡(ms-SG)还是文莱(ms-BN)?
Common ISO 639-1/BCP 47 Codes
常见ISO 639-1/BCP 47代码
For reference, see ISO_CODES.md for the complete list.
完整列表请参考 ISO_CODES.md。
Code Format
代码格式
Match the format used in the existing project:
- If project uses → use
en-US,fr-FR, etc.de-DE - If project uses → use
en_US,fr_FR, etc.de_DE - If project uses → use
en,fr, etc.de
匹配现有项目使用的格式:
- 如果项目使用 → 使用
en-US,fr-FR等de-DE - 如果项目使用 → 使用
en_US,fr_FR等de_DE - 如果项目使用 → 使用
en,fr等de
Step 3: Extract Source Strings
步骤3:提取源字符串
Load the English source file and parse all translatable strings. Note:
- Preserve keys exactly - Do not modify key names
- Note placeholders - ,
{name},{{count}},%s,%d, etc.%@ - Note HTML/markup - ,
<b>, etc.<a href="..."> - Note pluralization - ,
one,other,fewformsmany - Note context - ICU message format, gender variations, etc.
加载英文源文件并解析所有可翻译字符串。注意:
- 严格保留键名 - 不要修改键的名称
- 注意占位符 - ,
{name},{{count}},%s,%d等%@ - 注意HTML/标记 - ,
<b>等<a href="..."> - 注意复数形式 - ,
one,other,few形式many - 注意上下文 - ICU消息格式、性别变体等
Step 4: Dual Translation with Sub-Agents
步骤4:使用子Agent进行双重翻译
Delegate translation to two sub-agents: and .
translator-alphatranslator-beta将翻译任务委托给两个子Agent: 和 。
translator-alphatranslator-betaInstructions for Translators
翻译员说明
Both translators receive the same instructions (see TRANSLATOR_INSTRUCTIONS.md):
- You are a master linguist fluent in both English and {TARGET_LANGUAGE}
- Translate each string maintaining natural, idiomatic expression
- CRITICAL: Preserve all formatting exactly:
- Placeholders: ,
{variable},{{variable}},%s,%d,%1$s%@ - HTML tags: ,
<b>,<i>,<a href="..."><br/> - Special characters: ,
\n,\t,\"\' - Whitespace at start/end of strings
- Markdown formatting if present
- Placeholders:
- Adapt idioms appropriately - don't translate literally if unnatural
- Consider formality level (formal/informal "you" where applicable)
- Provide a confidence score (0.0-1.0) for each translation:
- 1.0: Certain, standard translation
- 0.8-0.9: High confidence, minor ambiguity
- 0.6-0.7: Moderate confidence, context-dependent
- Below 0.6: Low confidence, needs review
两个翻译员接收相同的指令(详见 TRANSLATOR_INSTRUCTIONS.md):
- 你是精通英文和{目标语言}的资深语言学家
- 翻译每个字符串时保持自然、地道的表达
- 关键要求:严格保留所有格式:
- 占位符:,
{variable},{{variable}},%s,%d,%1$s%@ - HTML标签:,
<b>,<i>,<a href="..."><br/> - 特殊字符:,
\n,\t,\"\' - 字符串首尾的空白字符
- 若存在Markdown格式,需保留
- 占位符:
- 适当调整习语 - 如果直译不自然,不要直译
- 考虑正式程度(适用时区分正式/非正式的“你”)
- 为每个翻译提供置信度评分(0.0-1.0):
- 1.0:确定,标准翻译
- 0.8-0.9:高置信度,轻微歧义
- 0.6-0.7:中等置信度,依赖上下文
- 低于0.6:低置信度,需要审核
Output Format from Translators
翻译员输出格式
Each translator returns:
json
{
"translations": [
{
"key": "original.key",
"source": "English text",
"translation": "Translated text",
"confidence": 0.95,
"notes": "Optional notes about translation choices"
}
]
}每个翻译员返回:
json
{
"translations": [
{
"key": "original.key",
"source": "English text",
"translation": "Translated text",
"confidence": 0.95,
"notes": "Optional notes about translation choices"
}
]
}Step 5: Verification with Adjudicator Sub-Agent
步骤5:使用裁决子Agent进行验证
The sub-agent receives:
translator-adjudicator- Original English strings
- Translation A (from translator-alpha) with confidence scores
- Translation B (from translator-beta) with confidence scores
translator-adjudicator- 原始英文字符串
- 翻译A(来自translator-alpha)及置信度评分
- 翻译B(来自translator-beta)及置信度评分
Adjudicator Instructions
裁决员说明
See ADJUDICATOR_INSTRUCTIONS.md for full details.
The adjudicator evaluates each string pair and selects the better translation based on:
- Accuracy - Does it convey the same meaning?
- Idiomaticity - Does it sound natural in the target language?
- Formatting preservation - Are all placeholders/tags intact?
- Consistency - Does terminology match across strings?
- Confidence scores - Factor in translator certainty
For each string, the adjudicator outputs:
json
{
"key": "original.key",
"selected": "A" | "B" | "merged",
"final_translation": "The selected or merged translation",
"reason": "Brief explanation of choice"
}完整详情请见 ADJUDICATOR_INSTRUCTIONS.md。
裁决员根据以下标准评估每对字符串并选择更优的翻译:
- 准确性 - 是否传达了相同的含义?
- 地道性 - 在目标语言中听起来是否自然?
- 格式保留 - 所有占位符/标签是否完整?
- 一致性 - 术语在所有字符串中是否一致?
- 置信度评分 - 考虑翻译员的确定性
对于每个字符串,裁决员输出:
json
{
"key": "original.key",
"selected": "A" | "B" | "merged",
"final_translation": "The selected or merged translation",
"reason": "Brief explanation of choice"
}Step 6: Generate Output File
步骤6:生成输出文件
Create the localization file in the correct format for the project:
创建符合项目要求格式的本地化文件:
JSON Format
JSON格式
json
{
"key1": "translation1",
"key2": "translation2"
}json
{
"key1": "translation1",
"key2": "translation2"
}YAML Format
YAML格式
yaml
target_locale:
key1: translation1
key2: translation2yaml
target_locale:
key1: translation1
key2: translation2iOS Strings Format
iOS Strings格式
/* Comment */
"key1" = "translation1";
"key2" = "translation2";/* Comment */
"key1" = "translation1";
"key2" = "translation2";Android XML Format
Android XML格式
xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="key1">translation1</string>
<string name="key2">translation2</string>
</resources>xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="key1">translation1</string>
<string name="key2">translation2</string>
</resources>PO Format
PO格式
msgid "source text"
msgstr "translation"msgid "source text"
msgstr "translation"Error Handling
错误处理
- Missing source file: Ask user to specify the English source location
- Ambiguous language: Always ask for clarification (see Step 2)
- Unknown format: Ask user about the localization framework
- Large files: Process in batches if over 200 strings
- 缺少源文件:请用户指定英文源文件的位置
- 语言模糊:务必询问以澄清(见步骤2)
- 未知格式:询问用户关于本地化框架的信息
- 大文件:如果超过200个字符串,分批处理
Quality Checklist
质量检查清单
Before finalizing, verify:
- All keys from source are present in output
- No extra keys were added
- All placeholders are preserved exactly
- File encoding matches source (usually UTF-8)
- File format matches project conventions
- Pluralization rules are correct for target language
最终确定前,请验证:
- 源文件中的所有键均在输出中存在
- 未添加额外的键
- 所有占位符均严格保留
- 文件编码与源文件匹配(通常为UTF-8)
- 文件格式符合项目约定
- 目标语言的复数规则正确