feat: 更新 Crowdin 工作流以支持 dashboard WebUI 的本地化文件,添加相关验证逻辑

This commit is contained in:
春河晴
2026-03-13 20:09:21 +09:00
parent 5f5ff4ce8e
commit 5da82c4e24
8 changed files with 283 additions and 15 deletions

View File

@@ -41,6 +41,7 @@ Only source-language assets should trigger source uploads to Crowdin.
Current source-language assets:
- `locales/zh-CN/*.json`
- `prompts/zh-CN/**/*.prompt`
- `dashboard/src/i18n/locales/zh.json`
- `crowdin.yml`
### Prompt template extension
@@ -162,6 +163,9 @@ This workflow must remain the repository-side structural validation layer for lo
#### Required validation role
It should validate localization assets and i18n-relevant code changes.
That includes both:
- backend locale JSON under `locales/`
- dashboard locale JSON under `dashboard/src/i18n/locales/`
#### Prompt trigger scope
It must cover the actual prompt template extension used in the repository.

View File

@@ -37,7 +37,9 @@ External prerequisite:
- source locale for JSON translations: `locales/zh-CN/*.json`
- source locale for prompt templates: `prompts/zh-CN/**/*.prompt`
- source locale for dashboard WebUI translations: `dashboard/src/i18n/locales/zh.json`
- current prompt template extension in the repository: `.prompt`
- dashboard WebUI keeps short runtime locale filenames (`zh`, `en`, `ja`, `ko`) in Git, but `dashboard/src/i18n/locales/zh.json` is still the repository-side `zh-CN` source asset for that file group
Normal push-triggered source uploads remain strictly source-driven.
Translated target assets are not part of the steady-state upload trigger set.
@@ -94,6 +96,7 @@ Triggers:
- `crowdin.yml`
- `locales/zh-CN/*.json`
- `prompts/zh-CN/**/*.prompt`
- `dashboard/src/i18n/locales/zh.json`
Branch behavior:
@@ -127,6 +130,8 @@ Triggers:
- pull requests that touch:
- `locales/**/*.json`
- `prompts/**/*.prompt`
- `dashboard/src/i18n/index.ts`
- `dashboard/src/i18n/locales/*.json`
- `scripts/i18n_validate.py`
- `src/common/i18n/**/*.py`
- `src/common/prompt_i18n.py`
@@ -136,7 +141,9 @@ Triggers:
Validation scope:
- JSON locale key alignment against `zh-CN`
- dashboard nested JSON locale key alignment against `dashboard/src/i18n/locales/zh.json`
- placeholder consistency
- dashboard i18next interpolation placeholder consistency
- plural structure consistency
- prompt placeholder consistency
- English locale protection against Chinese source-language leakage
@@ -192,7 +199,7 @@ Effect:
### B. Normal source-language update on `main` or `r-dev`
1. A source-language change is pushed to `main` or `r-dev`.
2. `crowdin-sync.yml` uploads `zh-CN` source assets to Crowdin.
2. `crowdin-sync.yml` uploads source-language assets to Crowdin, including the dashboard WebUI source file `dashboard/src/i18n/locales/zh.json`.
3. The same workflow may also download any translations currently available in Crowdin when that workflow run executes.
4. A localization pull request is opened or updated:
- `l10n_main -> main`
@@ -218,6 +225,7 @@ Effect:
- `crowdin.yml`
- `locales/zh-CN/*.json`
- `prompts/zh-CN/**/*.prompt`
- `dashboard/src/i18n/locales/zh.json`
- translated target files do not trigger another steady-state upload cycle
- the bootstrap path is manual and confirmation-gated
- translations return through `l10n_` branches and PRs instead of direct pushes to base branches

View File

@@ -37,6 +37,22 @@ prompts/
- 不要把 `zh-CN` 原文整批复制到 `prompts/en-US/` 后直接提交。
- 目标语言 prompt 文件应该由 Crowdin 下载生成;在本地还没有目标文件时,运行时会自动回退到 `zh-CN`
Dashboard WebUI 的 locale 文件位于 `dashboard/src/i18n/locales/*.json`
```text
dashboard/src/i18n/locales/
zh.json
en.json
ja.json
ko.json
```
注意:
- `dashboard/src/i18n/locales/zh.json` 是 dashboard 在 Git 中的 source of truth。
- dashboard 运行时继续使用 `zh` / `en` / `ja` / `ko` 这组短 locale code但 Crowdin 侧仍把 `zh.json` 当作仓库里的 `zh-CN` source 资产来同步。
- `en.json` / `ja.json` / `ko.json` 是同步产物和可评审输出,不是常规长期手工编辑面。
## 在代码中使用
统一从 [`src/common/i18n/__init__.py`](../src/common/i18n/__init__.py) 导入:
@@ -88,7 +104,7 @@ Prompt 加载规则:
## 日常翻译流程
1. 先在 `locales/zh-CN/*.json``prompts/zh-CN/**/*.prompt` 添加或修改 source 内容。
1. 先在 `locales/zh-CN/*.json``prompts/zh-CN/**/*.prompt``dashboard/src/i18n/locales/zh.json` 添加或修改 source 内容。
2. 在代码中用 `t()` / `tn()` / `load_prompt()` 替换硬编码字符串。
3. 运行 `python scripts/i18n_validate.py` 校验结构。
4. 把 source 变更推送到 `main``r-dev`,或手动触发 [`crowdin-sync.yml`](../.github/workflows/crowdin-sync.yml)。
@@ -100,6 +116,7 @@ Prompt 加载规则:
- 下面这两条是本仓库的 repository-specific 校验策略,不是 Crowdin 默认行为。
- 不要手工把中文 source 文案直接复制进目标语言文件后提交。
- 英文 locale 文件中不应保留中文字符;这类残留会被校验脚本拦截。
- `dashboard/src/i18n/locales/en.json` / `ja.json` / `ko.json` 也遵循同样规则。
### 什么时候可以直接改目标语言文件
@@ -124,7 +141,9 @@ python scripts/i18n_validate.py
- 是否存在重复 key
- 是否存在空字符串 key
- 各语言 key 集合是否与 `zh-CN` 对齐
- dashboard 嵌套 JSON 的 key 集合是否与 `dashboard/src/i18n/locales/zh.json` 对齐
- 占位符集合是否一致
- dashboard i18next `{{placeholder}}` 占位符集合是否一致
- plural 结构是否一致
-`zh-CN` locale 是否直接保留了包含中文字符的 source 文案
- prompt 模板已存在时,其占位符集合必须与 `prompts/zh-CN/` 对齐
@@ -146,12 +165,20 @@ python scripts/i18n_extract_candidates.py
## Crowdin
项目根目录的 [`crowdin.yml`](../crowdin.yml) 使用 `locales/zh-CN/*.json` 作为 source
现在也会把 `prompts/zh-CN/**/*.prompt` 作为单文件 Prompt 模板 source 上传到 Crowdin。
项目根目录的 [`crowdin.yml`](../crowdin.yml) 现在会上传三类 source
- `locales/zh-CN/*.json`
- `prompts/zh-CN/**/*.prompt`
- `dashboard/src/i18n/locales/zh.json`
对于 dashboard
- Crowdin 下载结果会回写到 `dashboard/src/i18n/locales/en.json``ja.json``ko.json`
- 其中英文文件名保持为 `en.json`,但在 Crowdin 配置里仍映射到 `en-US`
GitHub Actions 中的 [`crowdin-sync.yml`](../.github/workflows/crowdin-sync.yml) 是日常稳态同步入口:
- push 到 `main` / `r-dev` 时,只有 `zh-CN` source 资产`crowdin.yml` 会触发正常上传。
- push 到 `main` / `r-dev` 时,只有 source 资产(包括 dashboard 的 `zh.json` source 文件)`crowdin.yml` 会触发正常上传。
- workflow 运行时会上传 source并下载当时 Crowdin 中可用的翻译结果。
- 下载结果通过 `l10n_*` pull request 回流,而不是直接写回 `main` / `r-dev`