localization

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Software Localization Skill

软件本地化Skill

This skill creates high-quality localizations for software projects by using a dual-translation approach with verification.
本技能通过带验证的双重翻译方法,为软件项目创建高质量的本地化内容。

Workflow Overview

工作流程概述

  1. Detect Project Type - Identify the localization framework and file format
  2. Validate Target Language - Ensure a valid ISO 639 language code is provided
  3. Extract Source Strings - Load English (en/en-us/en_us) as the base
  4. Dual Translation - Two independent translator sub-agents produce translations
  5. Verification - A third sub-agent compares results and selects the best translations
  6. Output - Generate the localization file in the correct format
  1. 检测项目类型 - 识别本地化框架和文件格式
  2. 验证目标语言 - 确保提供有效的ISO 639语言代码
  3. 提取源字符串 - 以英文(en/en-us/en_us)作为基准加载
  4. 双重翻译 - 两个独立的翻译子Agent生成翻译内容
  5. 验证 - 第三个子Agent对比结果并选择最佳翻译
  6. 输出 - 生成正确格式的本地化文件

Step 1: Detect Project Type

步骤1:检测项目类型

Before any translation work, identify the localization system by examining the project structure.
在进行任何翻译工作之前,通过检查项目结构识别本地化系统。

Common Patterns to Check

需检查的常见模式

FrameworkLocationFormatKey Pattern
React (react-i18next)
public/locales/
,
src/locales/
JSON
{"key": "value"}
React (react-intl)
src/translations/
,
lang/
JSON
{"key": {"defaultMessage": "..."}}
Vue (vue-i18n)
src/locales/
,
locales/
JSON/YAML
{"key": "value"}
Angular
src/assets/i18n/
,
src/locale/
JSON/XLIFFJSON or XML-based
iOS
*.lproj/Localizable.strings
Strings
"key" = "value";
Android
res/values-*/strings.xml
XML
<string name="key">value</string>
Rails (i18n)
config/locales/
YAML
en:\n  key: value
Django
locale/*/LC_MESSAGES/
PO/POT
msgid "key"\nmsgstr "value"
.NET (resx)
Resources/
,
*.resx
XML
<data name="key"><value>...</value></data>
Flutter
lib/l10n/
,
assets/translations/
ARB/JSON
{"key": "value", "@key": {...}}
Go (go-i18n)
locales/
,
translations/
JSON/TOMLVarious
PHP (Laravel)
resources/lang/
PHP/JSON
return ['key' => 'value'];
Next.js
messages/
,
locales/
JSON
{"namespace": {"key": "value"}}
Gettext
*.po
,
*.pot
PO
msgid/msgstr
pairs
框架位置格式键模式
React (react-i18next)
public/locales/
,
src/locales/
JSON
{"key": "value"}
React (react-intl)
src/translations/
,
lang/
JSON
{"key": {"defaultMessage": "..."}}
Vue (vue-i18n)
src/locales/
,
locales/
JSON/YAML
{"key": "value"}
Angular
src/assets/i18n/
,
src/locale/
JSON/XLIFFJSON或基于XML
iOS
*.lproj/Localizable.strings
Strings
"key" = "value";
Android
res/values-*/strings.xml
XML
<string name="key">value</string>
Rails (i18n)
config/locales/
YAML
en:\n  key: value
Django
locale/*/LC_MESSAGES/
PO/POT
msgid "key"\nmsgstr "value"
.NET (resx)
Resources/
,
*.resx
XML
<data name="key"><value>...</value></data>
Flutter
lib/l10n/
,
assets/translations/
ARB/JSON
{"key": "value", "@key": {...}}
Go (go-i18n)
locales/
,
translations/
JSON/TOML多种格式
PHP (Laravel)
resources/lang/
PHP/JSON
return ['key' => 'value'];
Next.js
messages/
,
locales/
JSON
{"namespace": {"key": "value"}}
Gettext
*.po
,
*.pot
PO
msgid/msgstr
键值对

Detection Commands

检测命令

bash
undefined
bash
undefined

Find 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
undefined
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
undefined

Important: Examine the English Source

重要提示:检查英文源文件

Once you locate the localization directory, find the English source file. It may be named:
  • en.json
    ,
    en-US.json
    ,
    en_US.json
  • en.yaml
    ,
    en-US.yaml
  • en.lproj/Localizable.strings
  • values/strings.xml
    (Android default)
  • en.po
    ,
    messages.pot
Read this file to understand the structure before proceeding.
定位到本地化目录后,找到英文源文件。它可能命名为:
  • en.json
    ,
    en-US.json
    ,
    en_US.json
  • en.yaml
    ,
    en-US.yaml
  • en.lproj/Localizable.strings
  • values/strings.xml
    (Android默认)
  • en.po
    ,
    messages.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
    en-US
    → use
    fr-FR
    ,
    de-DE
    , etc.
  • If project uses
    en_US
    → use
    fr_FR
    ,
    de_DE
    , etc.
  • If project uses
    en
    → use
    fr
    ,
    de
    , etc.
匹配现有项目使用的格式:
  • 如果项目使用
    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>
    ,
    <a href="...">
    , etc.
  • Note pluralization -
    one
    ,
    other
    ,
    few
    ,
    many
    forms
  • 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:
translator-alpha
and
translator-beta
.
将翻译任务委托给两个子Agent:
translator-alpha
translator-beta

Instructions for Translators

翻译员说明

Both translators receive the same instructions (see TRANSLATOR_INSTRUCTIONS.md):
  1. You are a master linguist fluent in both English and {TARGET_LANGUAGE}
  2. Translate each string maintaining natural, idiomatic expression
  3. 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
  4. Adapt idioms appropriately - don't translate literally if unnatural
  5. Consider formality level (formal/informal "you" where applicable)
  6. 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):
  1. 你是精通英文和{目标语言}的资深语言学家
  2. 翻译每个字符串时保持自然、地道的表达
  3. 关键要求:严格保留所有格式:
    • 占位符:
      {variable}
      ,
      {{variable}}
      ,
      %s
      ,
      %d
      ,
      %1$s
      ,
      %@
    • HTML标签:
      <b>
      ,
      <i>
      ,
      <a href="...">
      ,
      <br/>
    • 特殊字符:
      \n
      ,
      \t
      ,
      \"
      ,
      \'
    • 字符串首尾的空白字符
    • 若存在Markdown格式,需保留
  4. 适当调整习语 - 如果直译不自然,不要直译
  5. 考虑正式程度(适用时区分正式/非正式的“你”)
  6. 为每个翻译提供置信度评分(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
translator-adjudicator
sub-agent receives:
  • Original English strings
  • Translation A (from translator-alpha) with confidence scores
  • Translation B (from translator-beta) with confidence scores
translator-adjudicator
子Agent接收:
  • 原始英文字符串
  • 翻译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:
  1. Accuracy - Does it convey the same meaning?
  2. Idiomaticity - Does it sound natural in the target language?
  3. Formatting preservation - Are all placeholders/tags intact?
  4. Consistency - Does terminology match across strings?
  5. 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
裁决员根据以下标准评估每对字符串并选择更优的翻译:
  1. 准确性 - 是否传达了相同的含义?
  2. 地道性 - 在目标语言中听起来是否自然?
  3. 格式保留 - 所有占位符/标签是否完整?
  4. 一致性 - 术语在所有字符串中是否一致?
  5. 置信度评分 - 考虑翻译员的确定性
对于每个字符串,裁决员输出:
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: translation2
yaml
target_locale:
  key1: translation1
  key2: translation2

iOS 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)
  • 文件格式符合项目约定
  • 目标语言的复数规则正确