translate
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTranslation Skill
翻译技能
Translate new entries in XLF translation files by finding targets, locating source context, and proposing translations for review.
state="new"通过查找的目标条目、定位源上下文并提供翻译供审核,来翻译XLF翻译文件中的新条目。
state="new"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 file:
.xlf- Read the file content
- Parse to find all elements
<trans-unit> - Filter for those containing
<target state="new"> - Extract for each:
- attribute (translation ID)
id - content (English text)
<source> - content (current translation, may be empty or placeholder)
<target> - Any placeholder elements ()
<x .../>
针对每个变更的文件:
.xlf- 读取文件内容
- 解析以找到所有元素
<trans-unit> - 筛选出包含的元素
<target state="new"> - 为每个符合条件的元素提取:
- 属性(翻译ID)
id - 内容(英文文本)
<source> - 内容(当前翻译,可能为空或占位符)
<target> - 所有占位符元素()
<x .../>
Step 3: Find Source Context
步骤3:查找源上下文
For each translation ID, search for its usage in the codebase:
TypeScript files ( strings):
$localizebash
grep -r "@@{ID}:" --include="*.ts" apps/ libs/HTML files ( attributes):
i18nbash
grep -r "@@{ID}\"" --include="*.html" apps/ libs/Read the surrounding code (5-10 lines) to understand context.
针对每个翻译ID,在代码库中搜索其使用场景:
TypeScript文件(字符串):
$localizebash
grep -r "@@{ID}:" --include="*.ts" apps/ libs/HTML文件(属性):
i18nbash
grep -r "@@{ID}\"" --include="*.html" apps/ libs/读取周边代码(5-10行)以理解上下文。
Step 4: Generate & Review Translations
步骤4:生成并审核翻译
For each entry, present to the user:
state="new"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
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:
- Replace the element content with the approved translation
<target> - Change to
state="new"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文件:
- 用已通过的翻译替换元素的内容
<target> - 将改为
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 Pattern | Language | Native Name |
|---|---|---|
| German | Deutsch |
| French | Francais |
| Spanish | Espanol |
| Hungarian | Magyar |
通过文件名格式识别目标语言:
| 文件名格式 | 语言 | 本地名称 |
|---|---|---|
| 德语 | Deutsch |
| 法语 | Francais |
| 西班牙语 | Espanol |
| 匈牙利语 | Magyar |
Placeholder Handling
占位符处理
Critical: Preserve all XML placeholder elements exactly as they appear in the source. These include:
| Element | Purpose | Example |
|---|---|---|
| Angular interpolations | |
| Multiple interpolations | Second, third interpolation |
| Named placeholders | ICU expressions |
| Multiple placeholders | Additional placeholders |
| Line breaks | |
| Opening HTML tags | |
| Closing HTML tags | |
| Bold text start | |
| Bold text end | |
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占位符元素的原始格式。这些元素包括:
| 元素 | 用途 | 示例 |
|---|---|---|
| Angular插值表达式 | |
| 多个插值表达式 | 第二个、第三个插值 |
| 命名占位符 | ICU表达式 |
| 多个占位符 | 额外占位符 |
| 换行符 | |
| HTML开始标签 | |
| HTML结束标签 | |
| 粗体文本开始 | |
| 粗体文本结束 | |
带占位符的示例:
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
翻译指南
- Match existing tone: Review other translations in the file to maintain consistent style
- Preserve placeholders: Copy placeholder elements exactly, only translate surrounding text
- Consider context: Use the code context to understand how the text is used
- Domain terminology: Use standard terms for:
- Mobility/transport: commute, emissions, CO2, modal split
- UI elements: buttons, labels, tooltips
- Business terms: audit, score, analysis
- Formal vs informal: German typically uses formal "Sie" form in business software
- 匹配现有语气:查看文件中的其他翻译以保持风格一致
- 保留占位符:完全复制占位符元素,仅翻译周边文本
- 结合上下文:通过代码上下文理解文本的使用场景
- 领域术语:针对以下领域使用标准术语:
- 出行/交通:通勤、排放、CO₂、出行方式分担
- UI元素:按钮、标签、提示框
- 业务术语:审计、评分、分析
- 正式与非正式:德语在商务软件中通常使用正式的“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:
- Group by file for efficiency
- Show a summary of how many entries need translation per file
- Process entries one at a time, waiting for approval
- After all entries are reviewed, show summary of changes made
当有多个条目需要翻译时:
- 按文件分组以提升效率
- 展示每个文件中待翻译条目的数量汇总
- 逐条处理,等待审核通过
- 所有条目审核完成后,展示已做变更的汇总
Error Handling
错误处理
- If no changed translation files found: Inform user and suggest running
git status - If no entries found: Inform user that all translations are up to date
state="new" - 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" - 若未找到上下文:仍仅基于源文本提供翻译,并标注上下文缺失
- 若文件解析错误:报告错误并跳过有问题的文件