translate

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Translation Skill

翻译技能

Translate new entries in XLF translation files by finding
state="new"
targets, locating source context, and proposing translations for review.
通过查找
state="new"
的目标条目、定位源上下文并提供翻译供审核,来翻译XLF翻译文件中的新条目。

Workflow

工作流

Step 1: Find Changed Translation Files

步骤1:查找变更的翻译文件

Run these commands to find changed translation files:
bash
git diff --name-only | grep -E 'messages\.[a-z]{2}\.xlf$'
git diff --cached --name-only | grep -E 'messages\.[a-z]{2}\.xlf$'
Combine results and deduplicate. If no changed translation files found, inform the user.
运行以下命令查找变更的翻译文件:
bash
git diff --name-only | grep -E 'messages\.[a-z]{2}\.xlf$'
git diff --cached --name-only | grep -E 'messages\.[a-z]{2}\.xlf$'
合并结果并去重。如果未找到变更的翻译文件,告知用户。

Step 2: Extract New Translations

步骤2:提取待翻译新条目

For each changed
.xlf
file:
  1. Read the file content
  2. Parse to find all
    <trans-unit>
    elements
  3. Filter for those containing
    <target state="new">
  4. Extract for each:
    • id
      attribute (translation ID)
    • <source>
      content (English text)
    • <target>
      content (current translation, may be empty or placeholder)
    • Any placeholder elements (
      <x .../>
      )
针对每个变更的
.xlf
文件:
  1. 读取文件内容
  2. 解析以找到所有
    <trans-unit>
    元素
  3. 筛选出包含
    <target state="new">
    的元素
  4. 为每个符合条件的元素提取:
    • id
      属性(翻译ID)
    • <source>
      内容(英文文本)
    • <target>
      内容(当前翻译,可能为空或占位符)
    • 所有占位符元素(
      <x .../>

Step 3: Find Source Context

步骤3:查找源上下文

For each translation ID, search for its usage in the codebase:
TypeScript files (
$localize
strings):
bash
grep -r "@@{ID}:" --include="*.ts" apps/ libs/
HTML files (
i18n
attributes):
bash
grep -r "@@{ID}\"" --include="*.html" apps/ libs/
Read the surrounding code (5-10 lines) to understand context.
针对每个翻译ID,在代码库中搜索其使用场景:
TypeScript文件
$localize
字符串):
bash
grep -r "@@{ID}:" --include="*.ts" apps/ libs/
HTML文件
i18n
属性):
bash
grep -r "@@{ID}\"" --include="*.html" apps/ libs/
读取周边代码(5-10行)以理解上下文。

Step 4: Generate & Review Translations

步骤4:生成并审核翻译

For each
state="new"
entry, present to the user:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Translation ID: {id}
File: {xlf_file_path}
Target Language: {language_name}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Source (English):
  {source_text}

Context:
  {file_path}:{line_number}
  {code_snippet}

Proposed Translation:
  {proposed_translation}

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Wait for user confirmation before proceeding. Options:
  • Accept the proposed translation
  • Provide an alternative translation
  • Skip this entry
针对每个
state="new"
的条目,向用户展示:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
翻译ID: {id}
文件: {xlf_file_path}
目标语言: {language_name}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

源文本(英文):
  {source_text}

上下文:
  {file_path}:{line_number}
  {code_snippet}

建议翻译:
  {proposed_translation}

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
等待用户确认后再继续。选项:
  • 接受建议的翻译
  • 提供替代翻译
  • 跳过此条目

Step 5: Apply Approved Translations

步骤5:应用已通过审核的翻译

For approved translations, update the XLF file:
  1. Replace the
    <target>
    element content with the approved translation
  2. Change
    state="new"
    to
    state="ai"
Before:
xml
<trans-unit id="myTranslationId" datatype="html">
  <source>English text</source>
  <target state="new">Old or empty translation</target>
</trans-unit>
After:
xml
<trans-unit id="myTranslationId" datatype="html">
  <source>English text</source>
  <target state="ai">Translated text</target>
</trans-unit>
针对已通过审核的翻译,更新XLF文件:
  1. 用已通过的翻译替换
    <target>
    元素的内容
  2. state="new"
    改为
    state="ai"
修改前:
xml
<trans-unit id="myTranslationId" datatype="html">
  <source>English text</source>
  <target state="new">Old or empty translation</target>
</trans-unit>
修改后:
xml
<trans-unit id="myTranslationId" datatype="html">
  <source>English text</source>
  <target state="ai">Translated text</target>
</trans-unit>

Language Detection

语言检测

Identify the target language from the filename pattern:
Filename PatternLanguageNative Name
messages.de.xlf
GermanDeutsch
messages.fr.xlf
FrenchFrancais
messages.es.xlf
SpanishEspanol
messages.hu.xlf
HungarianMagyar
通过文件名格式识别目标语言:
文件名格式语言本地名称
messages.de.xlf
德语Deutsch
messages.fr.xlf
法语Francais
messages.es.xlf
西班牙语Espanol
messages.hu.xlf
匈牙利语Magyar

Placeholder Handling

占位符处理

Critical: Preserve all XML placeholder elements exactly as they appear in the source. These include:
ElementPurposeExample
<x id="INTERPOLATION" equiv-text="{{...}}"/>
Angular interpolations
{{count}}
<x id="INTERPOLATION_n"/>
Multiple interpolationsSecond, third interpolation
<x id="PH" equiv-text="..."/>
Named placeholdersICU expressions
<x id="PH_n"/>
Multiple placeholdersAdditional placeholders
<x id="LINE_BREAK" ctype="lb"/>
Line breaks
<br>
<x id="START_TAG_SPAN"/>
Opening HTML tags
<span>
<x id="CLOSE_TAG_SPAN"/>
Closing HTML tags
</span>
<x id="START_BOLD_TEXT"/>
Bold text start
<b>
<x id="CLOSE_BOLD_TEXT"/>
Bold text end
</b>
Example with placeholders:
xml
<source>Hello <x id="INTERPOLATION" equiv-text="{{name}}"/>, you have <x id="INTERPOLATION_1" equiv-text="{{count}}"/> messages.</source>
<target state="ai">Hallo <x id="INTERPOLATION" equiv-text="{{name}}"/>, Sie haben <x id="INTERPOLATION_1" equiv-text="{{count}}"/> Nachrichten.</target>
关键要求:完全保留所有XML占位符元素的原始格式。这些元素包括:
元素用途示例
<x id="INTERPOLATION" equiv-text="{{...}}"/>
Angular插值表达式
{{count}}
<x id="INTERPOLATION_n"/>
多个插值表达式第二个、第三个插值
<x id="PH" equiv-text="..."/>
命名占位符ICU表达式
<x id="PH_n"/>
多个占位符额外占位符
<x id="LINE_BREAK" ctype="lb"/>
换行符
<br>
<x id="START_TAG_SPAN"/>
HTML开始标签
<span>
<x id="CLOSE_TAG_SPAN"/>
HTML结束标签
</span>
<x id="START_BOLD_TEXT"/>
粗体文本开始
<b>
<x id="CLOSE_BOLD_TEXT"/>
粗体文本结束
</b>
带占位符的示例:
xml
<source>Hello <x id="INTERPOLATION" equiv-text="{{name}}"/>, you have <x id="INTERPOLATION_1" equiv-text="{{count}}"/> messages.</source>
<target state="ai">Hallo <x id="INTERPOLATION" equiv-text="{{name}}"/>, Sie haben <x id="INTERPOLATION_1" equiv-text="{{count}}"/> Nachrichten.</target>

Translation Guidelines

翻译指南

  1. Match existing tone: Review other translations in the file to maintain consistent style
  2. Preserve placeholders: Copy placeholder elements exactly, only translate surrounding text
  3. Consider context: Use the code context to understand how the text is used
  4. Domain terminology: Use standard terms for:
    • Mobility/transport: commute, emissions, CO2, modal split
    • UI elements: buttons, labels, tooltips
    • Business terms: audit, score, analysis
  5. Formal vs informal: German typically uses formal "Sie" form in business software
  1. 匹配现有语气:查看文件中的其他翻译以保持风格一致
  2. 保留占位符:完全复制占位符元素,仅翻译周边文本
  3. 结合上下文:通过代码上下文理解文本的使用场景
  4. 领域术语:针对以下领域使用标准术语:
    • 出行/交通:通勤、排放、CO₂、出行方式分担
    • UI元素:按钮、标签、提示框
    • 业务术语:审计、评分、分析
  5. 正式与非正式:德语在商务软件中通常使用正式的“Sie”称谓

Common Translation Patterns

常见翻译示例

German (de)

德语 (de)

  • "Save" → "Speichern"
  • "Cancel" → "Abbrechen"
  • "Loading..." → "Wird geladen..."
  • "Error" → "Fehler"
  • "Success" → "Erfolgreich"
  • "Save" → "Speichern"
  • "Cancel" → "Abbrechen"
  • "Loading..." → "Wird geladen..."
  • "Error" → "Fehler"
  • "Success" → "Erfolgreich"

French (fr)

法语 (fr)

  • "Save" → "Enregistrer"
  • "Cancel" → "Annuler"
  • "Loading..." → "Chargement..."
  • "Error" → "Erreur"
  • "Success" → "Succes"
  • "Save" → "Enregistrer"
  • "Cancel" → "Annuler"
  • "Loading..." → "Chargement..."
  • "Error" → "Erreur"
  • "Success" → "Succès"

Spanish (es)

西班牙语 (es)

  • "Save" → "Guardar"
  • "Cancel" → "Cancelar"
  • "Loading..." → "Cargando..."
  • "Error" → "Error"
  • "Success" → "Exito"
  • "Save" → "Guardar"
  • "Cancel" → "Cancelar"
  • "Loading..." → "Cargando..."
  • "Error" → "Error"
  • "Success" → "Éxito"

Hungarian (hu)

匈牙利语 (hu)

  • "Save" → "Mentes"
  • "Cancel" → "Megse"
  • "Loading..." → "Betoltes..."
  • "Error" → "Hiba"
  • "Success" → "Sikeres"
  • "Save" → "Mentés"
  • "Cancel" → "Mégse"
  • "Loading..." → "Betöltés..."
  • "Error" → "Hiba"
  • "Success" → "Sikeres"

Batch Processing

批量处理

When multiple entries need translation:
  1. Group by file for efficiency
  2. Show a summary of how many entries need translation per file
  3. Process entries one at a time, waiting for approval
  4. After all entries are reviewed, show summary of changes made
当有多个条目需要翻译时:
  1. 按文件分组以提升效率
  2. 展示每个文件中待翻译条目的数量汇总
  3. 逐条处理,等待审核通过
  4. 所有条目审核完成后,展示已做变更的汇总

Error Handling

错误处理

  • If no changed translation files found: Inform user and suggest running
    git status
  • If no
    state="new"
    entries found: Inform user that all translations are up to date
  • If context not found: Still propose translation based on source text alone, note missing context
  • If file parse error: Report the error and skip the problematic file
  • 若未找到变更的翻译文件:告知用户并建议运行
    git status
  • 若未找到
    state="new"
    的条目:告知用户所有翻译均已更新至最新状态
  • 若未找到上下文:仍仅基于源文本提供翻译,并标注上下文缺失
  • 若文件解析错误:报告错误并跳过有问题的文件