Skip to content

Commit e4e74d2

Browse files
committed
feat: replace cloud translation with local Argos
1 parent a667bbb commit e4e74d2

34 files changed

Lines changed: 3080 additions & 1323 deletions

.github/workflows/pages.yml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
deploy:
1919
name: Build and deploy
2020
runs-on: ubuntu-latest
21-
timeout-minutes: 15
21+
timeout-minutes: 45
2222
environment:
2323
name: github-pages
2424
url: ${{ steps.deployment.outputs.page_url }}
@@ -35,19 +35,27 @@ jobs:
3535
node-version: 24
3636
cache: yarn
3737

38+
- name: Set up Python
39+
uses: actions/setup-python@v6
40+
with:
41+
python-version: "3.12"
42+
cache: pip
43+
cache-dependency-path: requirements-i18n.txt
44+
3845
- name: Install dependencies
3946
run: corepack yarn install --frozen-lockfile
4047

48+
- name: Install offline translation engine
49+
run: python -m pip install --disable-pip-version-check -r requirements-i18n.txt
50+
51+
- name: Restore Argos language model
52+
uses: actions/cache@v5
53+
with:
54+
path: ~/.local/share/argos-translate
55+
key: argos-${{ runner.os }}-zh-en-1.9
56+
4157
- name: Synchronize English documentation
42-
env:
43-
AZURE_TRANSLATOR_KEY: ${{ secrets.AZURE_TRANSLATOR_KEY }}
44-
AZURE_TRANSLATOR_REGION: ${{ vars.AZURE_TRANSLATOR_REGION }}
45-
run: |
46-
if [ -z "$AZURE_TRANSLATOR_KEY" ]; then
47-
echo "::warning::AZURE_TRANSLATOR_KEY is not configured; using the checked-in English pages."
48-
exit 0
49-
fi
50-
corepack yarn translate
58+
run: corepack yarn translate
5159

5260
- name: Build site
5361
run: corepack yarn build
@@ -67,8 +75,8 @@ jobs:
6775
- name: Save generated English documentation
6876
run: |
6977
git add -- docs/uk
70-
if [ -f .i18n-cache/azure-en.json ]; then
71-
git add -- .i18n-cache/azure-en.json
78+
if [ -f .i18n-cache/argos-zh-en.json ]; then
79+
git add -- .i18n-cache/argos-zh-en.json
7280
fi
7381
if git diff --cached --quiet; then
7482
exit 0

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
node_modules/
22
dist/
3+
__pycache__/
4+
.venv*/
5+
.argos-runtime/
36
*.log
47
.env
58
.env.*

.i18n-cache/argos-zh-en.json

Lines changed: 1399 additions & 0 deletions
Large diffs are not rendered by default.

TRANSLATING.md

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,43 @@
22

33
中文 `docs` 目录是本站内容的唯一来源。`docs/uk` 中的英文 Markdown 由构建流程生成,请不要直接编辑。
44

5-
## 首次启用
5+
## 实现方式
66

7-
1. 在 Azure 中创建单服务 **Translator** 资源,区域选择 **Global**,定价层选择 **Free F0**
8-
2. 在资源的 **Keys and Endpoint** 页面复制其中一个密钥。
9-
3. 打开 GitHub 仓库的 **Settings → Secrets and variables → Actions**
10-
4. 新建名为 `AZURE_TRANSLATOR_KEY` 的 Repository secret,并填入 Azure Translator 密钥。
11-
5. 如果资源不是 Global 区域,再创建名为 `AZURE_TRANSLATOR_REGION` 的 Repository variable,值为资源区域代码。
12-
6. 在 GitHub Actions 中手动运行一次 **Deploy documentation**,或推送一次中文文档修改。
7+
翻译完全使用开源的 [Argos Translate](https://github.com/argosopentech/argos-translate) 在本地完成,不调用在线翻译 API,也不需要注册账号、添加密钥或绑定付款方式。
138

14-
密钥只提供给 GitHub Actions,不会写入仓库、生成文件或浏览器代码。
9+
- 翻译引擎:Argos Translate 1.11.0(MIT)
10+
- 语言模型:`translate-zh_en` 1.9
11+
- 运行位置:开发者本机或 GitHub Actions Runner
12+
- 外部请求:仅在首次安装时下载 Python 依赖和开源语言模型
13+
- 后续运行:只翻译未命中仓库缓存的新增或修改段落
14+
15+
GitHub Actions 会缓存语言模型,并把生成的英文页面与 `.i18n-cache/argos-zh-en.json` 一并提交回仓库。无需配置 Repository secret 或 variable。
1516

1617
## 同步规则
1718

1819
- 新增中文 Markdown:创建同路径英文页面。
19-
- 修改中文 Markdown:只请求翻译没有命中段落缓存的内容
20+
- 修改中文 Markdown:只翻译没有命中段落缓存的内容
2021
- 删除中文 Markdown:删除同路径英文页面。
21-
- 移动或重命名:表现为删除旧英文页面并创建新页面
22+
- 移动或重命名:删除旧英文页面并创建新页面
2223
- 代码块、行内代码、链接目标、图片地址和 HTML 注释保持原样。
2324
- 根路径文档链接自动增加 `/uk` 前缀。
24-
- `i18n.config.json` 中的 Arch Linux 术语保持原文。
25-
- API 请求失败时不写入部分翻译,也不会部署不完整版本。
25+
- `i18n.config.json` 中配置的项目品牌名称保持原文。
26+
- 翻译失败时不写入部分结果,也不会部署不完整版本。
27+
28+
## 本地运行
29+
30+
首次运行先安装 Python 依赖:
31+
32+
```bash
33+
python -m pip install -r requirements-i18n.txt
34+
```
35+
36+
然后执行:
37+
38+
```bash
39+
yarn translate
40+
```
41+
42+
第一次运行会自动下载固定版本的中英语言模型。以后日常只需要维护中文文档;英文页面和翻译缓存由自动化流程维护。
2643

27-
本地拥有 Azure Translator 密钥时,可以设置 `AZURE_TRANSLATOR_KEY` 环境变量后运行 `yarn translate`。区域资源还需设置 `AZURE_TRANSLATOR_REGION`;Global 资源可以省略。日常只需维护中文文档,英文生成文件和 `.i18n-cache` 缓存由 GitHub Actions 提交
44+
如果系统中的 Python 命令不是 `python``python3`,可以通过 `ARGOS_PYTHON` 环境变量指定解释器路径

0 commit comments

Comments
 (0)