国际化工作流
这篇文档约束这个仓库以后新增文档或博客时同步完成英文翻译的标准方式。
站点使用 Docusaurus 内置 i18n:zh-Hans 是默认语言,英文通过 i18n/en/ 目录实现。根目录的 I18N.md 是完整的参考手册,这篇文档只关心"每次新增内容时该怎么做"。
核心原则
1. 中文放 docs/ 和 blog/,英文放 i18n/en/ 镜像路径
中文是默认语言,直接放在项目根目录的 docs/ 和 blog/ 下。英文翻译放在 i18n/en/ 下的对应插件目录,路径必须 1:1 镜像。
文档镜像规则:
docs/Linux/new-article.md
→ i18n/en/docusaurus-plugin-content-docs/current/Linux/new-article.md
docs/DataStructer/sorting-algorithms/sorting-basics.md
→ i18n/en/docusaurus-plugin-content-docs/current/DataStructer/sorting-algorithms/sorting-basics.md
博客镜像规则:
blog/2026-05-01-new-post.md
→ i18n/en/docusaurus-plugin-content-blog/2026-05-01-new-post.md
文件名必须完全一致,包括大小写和扩展名。
2. 只翻译人读的文字,不翻译代码和技术标识
翻译范围:
| 内容 | 是否翻译 |
|---|---|
title、description | 翻译 |
sidebar_position、tags、authors、slug | 保持一致 |
| 正文段落、标题 | 翻译 |
代码块(```) | 不翻译 |
内联代码(`) | 不翻译 |
图片链接、JSX 组件、import / export | 不翻译 |
| LaTeX 公式 | 不翻译 |
3. 新目录必须同步创建 _category_.json
如果新增了一个目录(不管是文档目录还是专题目录),英文镜像路径下必须有对应的 _category_.json,position 保持一致,label 和 description 翻译。
// docs/NewDir/_category_.json
{
"label": "新目录",
"position": 12,
"link": {
"type": "generated-index",
"description": "中文描述。"
}
}
// i18n/en/.../NewDir/_category_.json
{
"label": "New Directory",
"position": 12,
"link": {
"type": "generated-index",
"description": "English description."
}
}
4. 新标签必须同步更新 tags.yml
如果文章使用了新标签,英文的 tags.yml 也要更新。permalink 保持一致,label 翻译。
5. 更新任何文档都必须同步更新英文翻译
不管是新增还是修改 docs/ 下的文档,都必须同步更新 i18n/en/ 下对应的英文版本。这条适用于所有 docs/ 下的 .md 和 .mdx 文件,包括工作流文档、LabNotes、技术指南等。
具体要求:
- 修改了中文文档的某一段,英文对应段必须同步修改
- 新增了一个章节,英文版必须新增对应章节
- 删除了内容,英文版也必须删除
- 不要只更新中文而留下英文版过时——这比不翻译更糟糕,因为读者会看到中英文不一致的文档
工作流类文档(如本文件、life-blog-writing-workflow.md)尤其重要,因为它们是后续工作的参考依据。如果中文版更新了流程但英文版没有,英文读者会遵循过时的流程。
# i18n/en/docusaurus-plugin-content-docs/current/tags.yml
New Tag:
label: New Tag
permalink: new-tag
标准流程:新增文档
第一步:创建中文文档
在 docs/ 下正常创建中文 .md 或 .mdx 文件。
第二步:创建英文翻译
在 i18n/en/docusaurus-plugin-content-docs/current/ 下创建同名同路径文件,翻译 frontmatter 和正文。
frontmatter 对照:
# 中文
---
title: 自定义镜像与 Dockerfile 实践
sidebar_position: 6
description: 把临时调试、Dockerfile 构建整理成一套更稳妥的工作流。
---
# 英文
---
title: Custom Images and Dockerfile Practices
sidebar_position: 6
description: "Turning ad-hoc debugging and Dockerfile builds into a more reliable workflow."
---
注意:description 包含冒号时必须用引号包裹,否则 YAML 解析会报错。
第三步:如果是新目录,同步创建英文 _category_.json
参照上面"核心原则"第 3 条。
第四步:如果使用了新标签,同步更新英文 tags.yml
参照上面"核心原则"第 4 条。
第五步:如果新标签名是中文,刷新 sidebar 翻译
npm run write-translations:en
然后编辑 i18n/en/docusaurus-plugin-content-docs/current.json,找到新增的 sidebar 条目翻译。