Files
market/.github/workflows/i18n-translate.yml
Yige 1f7c8b9673 feat: skills i18n 改造(schemaVersion 1.1,零向后兼容) (#1)
* feat: skills i18n 改造 — schemaVersion 1.1,零向后兼容

把 21 个 skills + 1 个 agent + manifest/categories 全量迁移到 schemaVersion 1.1
的 i18n 结构,配套 CI AI 翻译流水线(GitHub Models)与本地工具链。

## 关键变更

### 数据结构(破坏性,schemaVersion 1.0 → 1.1)
- SKILL.md: 顶层 name 改为 ASCII slug(== 目录名,符合 agentskills.io 规范);
  中文显示名/short_desc/description 全部迁入 metadata.i18n.<locale>
- agents/<id>/agent.json: shortDesc/fullDesc/tags/persona.{role,traits} 迁入
  i18n.<locale>;changelog[].changes 改为 { <locale>: string[] } 对象
- categories.json: 每个分类的 label/description 迁入 i18n.<locale>,顶层只剩
  color/icon
- manifest.json: 加 supportedLocales / defaultLocale;顶层 description 迁入
  i18n.<locale>

### Body 文件结构
- 根 SKILL.md = frontmatter + default_locale (en-US) body
- SKILL.<locale>.md = 各 locale 的 markdown body(首行 <!-- locale: xx --> 自校验)

### 工具链(scripts/i18n/)
- glossary.json: zh→en 术语表 + do_not_translate 白名单
- schema/skill-frontmatter.schema.json: i18n frontmatter JSON Schema
- validate-i18n.py: 8 条校验规则(name 合规 / locale 完整性 / hash 一致性等)
- translate.py: GitHub Models / Anthropic 双 backend,sha256 增量翻译
- migrate.py: 一次性迁移脚本(旧格式 → i18n 结构)

### CI(.github/workflows/)
- i18n-validate.yml: PR 触发跑 validate + translate --check
- i18n-translate.yml: PR 触发用 GitHub Models(默认 openai/gpt-5-mini)翻译缺失
  locale,自动追加 commit;可切到 ANTHROPIC_API_KEY 走 Claude

### 文档
- docs/I18N.md: 作者贡献指南(schema 说明 / 提交流程 / 常见问题)
- README.md: 加多语言段落

## 验证

- uv run scripts/i18n/validate-i18n.py: OK,49 文件 0 错误
- uv run scripts/i18n/translate.py --check: 0 stale locale
- 21 skills 标题数 zh-CN == en-US 严格对齐(最大 66=66)
- skills-ref 规范校验:全部通过(顶层 name ASCII slug + description 单字段)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(i18n): 修复 PR #1 review 反馈的 6 项问题

- schema: translated_by 正则放宽为 ^(human|ai:[A-Za-z0-9._:/-]+)$,接受
  'ai:github:openai/gpt-5-mini' 这类 backend:model 形式(CI 翻译输出格式)
- README + docs/I18N.md: 修正"CI 用 Claude API"误导描述,正确说明默认是
  GitHub Models(openai/gpt-5-mini)+ GITHUB_TOKEN,可选切到 Anthropic
- skills/minimax-tts/SKILL.md & SKILL.zh-CN.md: 删除多余的 ``` 闭合,避免
  Markdown 后续渲染错乱
- skills/docx/SKILL.md: 翻译时丢失的 • Unicode escape 示例已恢复,
  与 zh-CN 版本对齐

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 00:26:33 +08:00

157 lines
5.9 KiB
YAML

name: i18n Auto-Translate
# Uses GitHub Models inference API (https://models.github.ai/inference) with the
# repository's GITHUB_TOKEN. Requires `models: read` permission. Default model is
# openai/gpt-5-mini (a fast/cheap GPT-5 in the catalog); override via repository variable
# TRANSLATE_MODEL (e.g. openai/gpt-5-nano for cheaper, openai/gpt-5 for flagship).
#
# Optional: to use Anthropic Claude directly, add a repo secret ANTHROPIC_API_KEY,
# then set repository variable TRANSLATE_BACKEND=anthropic and TRANSLATE_MODEL to
# a Claude model id (e.g. claude-sonnet-4-6). Claude is NOT in the GitHub Models
# catalog as of 2026-05.
on:
pull_request:
paths:
- "skills/**/SKILL.zh-CN.md"
- "skills/**/SKILL.md"
- "manifest.json"
- "categories.json"
workflow_dispatch:
inputs:
target_locale:
description: "Target locale (default: all from manifest.supportedLocales)"
required: false
skill:
description: "Specific skill path, e.g. skills/web-access (default: all)"
required: false
permissions:
contents: write
pull-requests: write
models: read
concurrency:
group: i18n-translate-${{ github.ref }}
cancel-in-progress: true
jobs:
translate:
# Don't run on bot's own commits to avoid loops
if: github.actor != 'desirecore-bot[bot]' && !contains(github.event.head_commit.message, '[skip ci]')
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref || github.ref }}
token: ${{ secrets.DESIRECORE_BOT_TOKEN || secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Check for stale translations
id: precheck
run: |
set +e
uv run --quiet scripts/i18n/translate.py --check
rc=$?
if [ $rc -eq 0 ]; then
echo "stale=false" >> "$GITHUB_OUTPUT"
else
echo "stale=true" >> "$GITHUB_OUTPUT"
fi
exit 0
- name: Translate stale locales
if: steps.precheck.outputs.stale == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
TRANSLATE_BACKEND: ${{ vars.TRANSLATE_BACKEND || 'github' }}
TRANSLATE_MODEL: ${{ vars.TRANSLATE_MODEL || 'openai/gpt-5-mini' }}
run: |
set -e
ARGS=()
if [ -n "${{ github.event.inputs.skill }}" ]; then
ARGS+=("${{ github.event.inputs.skill }}")
fi
if [ -n "${{ github.event.inputs.target_locale }}" ]; then
ARGS+=(--target "${{ github.event.inputs.target_locale }}")
fi
uv run --quiet scripts/i18n/translate.py "${ARGS[@]}"
- name: Validate after translation
if: steps.precheck.outputs.stale == 'true'
run: uv run --quiet scripts/i18n/validate-i18n.py
- name: Detect changes
id: diff
if: steps.precheck.outputs.stale == 'true'
run: |
if git diff --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
git diff --stat
fi
- name: Commit & push translations
if: steps.diff.outputs.changed == 'true'
run: |
git config user.name "desirecore-bot"
git config user.email "bot@desirecore.net"
git add -A
git commit -m "chore(i18n): auto-translate skills [skip ci]" \
-m "Generated by scripts/i18n/translate.py via i18n-translate workflow." \
-m "Backend: ${TRANSLATE_BACKEND:-github} Model: ${TRANSLATE_MODEL:-openai/gpt-5-mini}"
git push
env:
TRANSLATE_BACKEND: ${{ vars.TRANSLATE_BACKEND || 'github' }}
TRANSLATE_MODEL: ${{ vars.TRANSLATE_MODEL || 'openai/gpt-5-mini' }}
- name: Comment on PR
if: steps.diff.outputs.changed == 'true' && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.DESIRECORE_BOT_TOKEN || secrets.GITHUB_TOKEN }}
script: |
const backend = process.env.TRANSLATE_BACKEND || 'github';
const model = process.env.TRANSLATE_MODEL || 'openai/gpt-5-mini';
const body = [
'🌐 **i18n auto-translation pushed**',
'',
'New machine-translated content was added to this PR by `scripts/i18n/translate.py`.',
'',
'**Please review the translated strings** before merging:',
'- Check terminology against `scripts/i18n/glossary.json`',
'- Verify Markdown structure (headings/tables/code fences) is preserved',
'- If you edit a translation, set `metadata.i18n.<locale>.translated_by: human` to lock it.',
'',
`Backend: \`${backend}\` Model: \`${model}\``,
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
env:
TRANSLATE_BACKEND: ${{ vars.TRANSLATE_BACKEND || 'github' }}
TRANSLATE_MODEL: ${{ vars.TRANSLATE_MODEL || 'openai/gpt-5-mini' }}
- name: Label on translation failure
if: failure() && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.DESIRECORE_BOT_TOKEN || secrets.GITHUB_TOKEN }}
script: |
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['i18n-translation-failed'],
});