name: Translate Documentation to Chinese on: push: branches: - main - development paths: - 'docs/**/*.md' - '!docs/zh-CN/**' - '!docs/archive/**' workflow_dispatch: inputs: files: description: 'Specific files to translate (comma-separated, or "all")' required: false default: 'changed' jobs: detect-changes: runs-on: ubuntu-latest outputs: changed-files: ${{ steps.detect.outputs.files }} steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 2 - name: Detect changed files id: detect run: | if [ "${{ github.event.inputs.files }}" = "all" ]; then # Translate all docs FILES=$(find docs -name "*.md" -not -path "docs/zh-CN/*" -not -path "docs/archive/*" | tr '\n' ',') elif [ "${{ github.event.inputs.files }}" != "" ] && [ "${{ github.event.inputs.files }}" != "changed" ]; then # Use provided files FILES="${{ github.event.inputs.files }}" else # Detect changed files FILES=$(git diff --name-only HEAD~1 HEAD | grep "^docs/" | grep -v "^docs/zh-CN/" | grep -v "^docs/archive/" | grep "\.md$" | tr '\n' ',') fi # Remove trailing comma FILES=$(echo "$FILES" | sed 's/,$//') echo "files=$FILES" >> $GITHUB_OUTPUT echo "Detected files: $FILES" translate: runs-on: ubuntu-latest needs: detect-changes if: needs.detect-changes.outputs.changed-files != '' steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.11' - name: Install dependencies run: | pip install anthropic - name: Translate documents env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} run: | IFS=',' read -ra FILES <<< "${{ needs.detect-changes.outputs.changed-files }}" for file in "${FILES[@]}"; do if [ -f "$file" ]; then echo "Translating: $file" python scripts/translate_doc.py "$file" --target-lang zh-CN || echo "Failed: $file" fi done - name: Check for changes id: git-check run: | git add docs/zh-CN/ if git diff --cached --quiet; then echo "changed=false" >> $GITHUB_OUTPUT else echo "changed=true" >> $GITHUB_OUTPUT fi - name: Create Pull Request if: steps.git-check.outputs.changed == 'true' uses: peter-evans/create-pull-request@v6 with: token: ${{ secrets.GITHUB_TOKEN }} commit-message: "[Auto] Chinese translation update" title: "🌐 [Auto] Chinese Documentation Translation Update" body: | ## 🇨🇳 中文文档翻译更新 / Chinese Documentation Translation Update This PR contains automated translations of updated documentation. ### 变更内容 / Changes ${{ needs.detect-changes.outputs.changed-files }} ### 审阅指南 / Review Guide - [ ] 技术术语准确 / Technical terms accurate - [ ] 链接正确指向中文版本 / Links point to Chinese versions - [ ] 代码示例保持原样 / Code examples preserved - [ ] 格式正确 / Formatting correct ### 如何审阅 / How to Review 1. 查看文件列表 / Check the file list 2. 阅读中文翻译 / Read the Chinese translation 3. 在 PR 中提出修改建议 / Suggest changes in PR 4. 确认后批准 / Approve when satisfied ### 相关 Issue - #260 - Chinese Translation --- *This PR was auto-generated by GitHub Actions* branch: auto-translate-zh-cn-${{ github.run_number }} delete-branch: true labels: translation, zh-CN, needs-review, automated - name: Update Issue #260 if: steps.git-check.outputs.changed == 'true' uses: actions/github-script@v7 with: script: | github.rest.issues.createComment({ issue_number: 260, owner: context.repo.owner, repo: context.repo.repo, body: `🤖 **自动翻译更新 / Automated Translation Update** 新的中文翻译已准备就绪,需要社区审阅: - PR: #${{ steps.create-pr.outputs.pull-request-number }} - 文件: ${{ needs.detect-changes.outputs.changed-files }} 请志愿者帮忙审阅,谢谢! / Community review needed, thanks!` })