doc-smith-localize
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDoc-Smith 文档翻译
Doc-Smith Document Translation
将文档翻译成多种语言,支持批量翻译和术语一致性。
Translate documents into multiple languages, supporting batch translation and terminology consistency.
用法
Usage
bash
/doc-smith-localize --lang en # 翻译所有文档到英文
/doc-smith-localize -l en -l ja # 翻译到多个语言
/doc-smith-localize -l en -p /overview # 只翻译指定文档
/doc-smith-localize -l en --force # 强制重新翻译
/doc-smith-localize -l en --skip-images # 跳过图片翻译bash
/doc-smith-localize --lang en # Translate all documents to English
/doc-smith-localize -l en -l ja # Translate to multiple languages
/doc-smith-localize -l en -p /overview # Translate only the specified document
/doc-smith-localize -l en --force # Force re-translation
/doc-smith-localize -l en --skip-images # Skip image translation选项
Options
| 选项 | 别名 | 说明 |
|---|---|---|
| | 目标语言代码(可多次使用) |
| | 指定文档路径(可多次使用) |
| | 强制重新翻译,覆盖已有 |
| 跳过图片翻译 |
| Option | Alias | Description |
|---|---|---|
| | Target language code (can be used multiple times) |
| | Specify document path (can be used multiple times) |
| | Force re-translation, overwrite existing translations |
| Skip image translation |
约束
Constraints
以下约束在任何操作中都必须满足。
The following constraints must be satisfied in all operations.
1. Workspace 约束
1. Workspace Constraints
- 和
.aigne/doc-smith/config.yaml必须存在planning/document-structure.yaml - 不存在时提示用户先使用 生成文档
/doc-smith
- and
.aigne/doc-smith/config.yamlmust existplanning/document-structure.yaml - If they do not exist, prompt the user to generate documents using first
/doc-smith
2. 参数验证约束
2. Parameter Validation Constraints
- 目标语言不能与源语言(config.yaml 的 locale)相同
- 指定的路径必须存在于 document-structure.yaml
--path - 过滤后无有效语言时报错
- Target language cannot be the same as the source language (locale in config.yaml)
- The path specified by must exist in document-structure.yaml
--path - Throw an error if no valid languages are left after filtering
3. 增量翻译约束
3. Incremental Translation Constraints
- 基于源 HTML 的 SHA256 hash(sourceHash)判断是否需要翻译
- hash 未变化的文档自动跳过(除非 )
--force - 翻译失败时不覆盖已有翻译、不修改 .meta.yaml
- Determine whether translation is needed based on the SHA256 hash (sourceHash) of the source HTML
- Automatically skip documents where the hash has not changed (unless is used)
--force - Do not overwrite existing translations or modify .meta.yaml if translation fails
4. Task 分发约束
4. Task Distribution Constraints
- 每个文档到每种语言为一个独立翻译任务
- 通过 Task(references/translate-document.md) 分发,并行执行
- 每批最多并行 5 个 Task,超过时分批执行
- 如有术语表(或
.aigne/doc-smith/glossary.yaml),传递给每个 Task.md
- Each document to each language is an independent translation task
- Distribute via Task(references/translate-document.md), execute in parallel
- Max 5 parallel Tasks per batch, split into batches if exceeded
- If a glossary exists (or
.aigne/doc-smith/glossary.yaml), pass it to each Task.md
5. 图片翻译约束
5. Image Translation Constraints
- 未指定 时,扫描 assets 中的图片资源
--skip-images - 跳过条件(满足任一):、目标语言已存在、源语言图片不存在
generation.shared: true - 使用 翻译图片文字
/doc-smith-images --update - 翻译后更新图片 .meta.yaml 的 languages 和 translations
- If is not specified, scan image resources in assets
--skip-images - Skip conditions (meet any): , target language already exists, source language image does not exist
generation.shared: true - Use to translate text in images
/doc-smith-images --update - Update the languages and translations fields in the image's .meta.yaml after translation
6. Config 更新约束
6. Config Update Constraints
- 翻译完成后,将目标语言添加到 config.yaml 的 数组
translateLanguages - 避免重复添加已存在的语言
- 更新后验证 config.yaml 正确
- After translation is completed, add the target language to the array in config.yaml
translateLanguages - Avoid adding existing languages repeatedly
- Verify that config.yaml is correct after update
7. nav.js 重建约束
7. nav.js Rebuild Constraints
- Config 更新后必须执行 nav.js 重建:
bash
node skills/doc-smith-build/scripts/build.mjs \ --nav --workspace .aigne/doc-smith --output .aigne/doc-smith/dist - 验证 包含所有目标语言的 code
dist/assets/nav.js - 此步骤是语言切换功能生效的关键,绝不能跳过
- Must rebuild nav.js after Config update:
bash
node skills/doc-smith-build/scripts/build.mjs \ --nav --workspace .aigne/doc-smith --output .aigne/doc-smith/dist - Verify that contains the codes of all target languages
dist/assets/nav.js - This step is critical for the language switch function to take effect and must not be skipped
HTML-to-HTML 翻译模型
HTML-to-HTML Translation Model
翻译直接在 HTML 层面完成,不经过 MD 中间步骤:
源 HTML → 提取可翻译区域 → 翻译 → 组装目标 HTML → 保存
dist/{source}/docs/{path}.html → dist/{target}/docs/{path}.html可翻译区域(4 个):
- 标签内文本
<title> - 的 content 属性
<meta name="description"> - 标签内 HTML
<main data-ds="content"> - 标签内 HTML
<nav data-ds="toc">
不翻译:head 资源引用、script、header/footer/sidebar、HTML 属性、代码块中的代码
Translation is done directly at the HTML level without going through an MD intermediate step:
Source HTML → Extract translatable regions → Translate → Assemble target HTML → Save
dist/{source}/docs/{path}.html → dist/{target}/docs/{path}.htmlTranslatable regions (4 types):
- Text inside tag
<title> - content attribute of
<meta name="description"> - HTML inside tag
<main data-ds="content"> - HTML inside tag
<nav data-ds="toc">
Not translated: head resource references, scripts, header/footer/sidebar, HTML attributes, code within code blocks
翻译质量要求
Translation Quality Requirements
- 术语一致性:使用术语表保持专业术语统一
- HTML 结构保持:标签原样保留,只翻译文本内容
- 上下文理解:根据技术文档语境选择合适译法
- 自然流畅:翻译结果符合目标语言习惯
- Terminology consistency: Use glossaries to maintain unified professional terms
- HTML structure preservation: Keep tags intact, only translate text content
- Context understanding: Choose appropriate translations based on the technical document context
- Natural fluency: Translation results conform to the target language's usage habits
关键流程
Key Processes
并行翻译文档
Parallel Document Translation
按 references/translate-document.md 流程使用单独的 Task tool 并行翻译以下文档:
- docPath=/overview, targetLanguage=en, sourceLanguage=zh, force=false
- docPath=/api/auth, targetLanguage=en, sourceLanguage=zh, force=falseUse separate Task tools to translate the following documents in parallel according to the references/translate-document.md process:
- docPath=/overview, targetLanguage=en, sourceLanguage=zh, force=false
- docPath=/api/auth, targetLanguage=en, sourceLanguage=zh, force=false翻译图片
Image Translation
bash
/doc-smith-images "将图片中的文字从 {source} 翻译成 {target},保持布局和风格不变" \
--update .aigne/doc-smith/assets/{key}/images/{source}.png \
--savePath .aigne/doc-smith/assets/{key}/images/{target}.png \
--locale {target}bash
/doc-smith-images "Translate text in images from {source} to {target}, keeping layout and style unchanged" \
--update .aigne/doc-smith/assets/{key}/images/{source}.png \
--savePath .aigne/doc-smith/assets/{key}/images/{target}.png \
--locale {target}更新图片引用
Update Image References
翻译后 HTML 中的图片路径需更新语言后缀:
- 匹配 → 替换为
images/{source}.png(仅当目标语言图片存在时)images/{target}.png
After translation, update the image paths in HTML with the language suffix:
- Match → replace with
images/{source}.png(only if the target language image exists)images/{target}.png
AI 巡检
AI Inspection
翻译和 nav.js 重建完成后,读取 中生成的 HTML 文件(每种语言各抽查 1-2 个页面),检查输出是否符合预期。如有问题直接修改 HTML 文件修复。
dist/After translation and nav.js rebuild, read the generated HTML files in (spot-check 1-2 pages per language) to verify if the output meets expectations. Directly modify the HTML files to fix any issues found.
dist/翻译报告
Translation Report
返回翻译结果摘要,包含文档和图片的翻译/跳过/失败统计。
Return a summary of translation results, including statistics on translated/skipped/failed documents and images.
错误处理
Error Handling
- Workspace 不存在:提示先使用 生成文档
/doc-smith - 目标语言与源语言相同:提示指定不同的语言
- 文档路径无效:列出有效路径供用户参考
- 翻译部分失败:报告失败文档,建议使用 单独重试
--path
- Workspace does not exist: Prompt the user to generate documents using first
/doc-smith - Target language is the same as source language: Prompt to specify a different language
- Invalid document path: List valid paths for user reference
- Partial translation failure: Report failed documents, suggest retrying individually with
--path