Skip to content

Add Wan2.7 Chinese and Japanese translations #18

Add Wan2.7 Chinese and Japanese translations

Add Wan2.7 Chinese and Japanese translations #18

name: Translation Sync
on:
# Trigger when a PR with 'needs-translation' label is merged into main
pull_request:
types: [closed]
branches:
- main
# Manual trigger for backfilling or re-running
workflow_dispatch:
inputs:
before_sha:
description: 'Before commit SHA (leave empty to use HEAD~1)'
required: false
after_sha:
description: 'After commit SHA (leave empty to use HEAD)'
required: false
pr_number:
description: 'PR number (for reference in translation PR body)'
required: false
jobs:
sync-translations:
# Only run if: merged PR with 'needs-translation' label, OR manual dispatch
if: |
github.event_name == 'workflow_dispatch' ||
(github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, 'needs-translation'))
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: pip install openai
- name: Determine commit range
id: commits
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
BEFORE="${{ github.event.inputs.before_sha }}"
AFTER="${{ github.event.inputs.after_sha }}"
PR_NUMBER="${{ github.event.inputs.pr_number }}"
if [ -z "$BEFORE" ]; then BEFORE=$(git rev-parse HEAD~1); fi
if [ -z "$AFTER" ]; then AFTER=$(git rev-parse HEAD); fi
else
# PR merge: compare base SHA with merge commit SHA
BEFORE="${{ github.event.pull_request.base.sha }}"
AFTER="${{ github.event.pull_request.merge_commit_sha }}"
PR_NUMBER="${{ github.event.pull_request.number }}"
fi
echo "before=$BEFORE" >> $GITHUB_OUTPUT
echo "after=$AFTER" >> $GITHUB_OUTPUT
echo "short_sha=$(echo $AFTER | cut -c1-7)" >> $GITHUB_OUTPUT
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "pr_title=${{ github.event.pull_request.title }}" >> $GITHUB_OUTPUT
- name: Run translation sync
id: translate
env:
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
run: |
python .github/scripts/translate-sync.py \
--before ${{ steps.commits.outputs.before }} \
--after ${{ steps.commits.outputs.after }} \
--output-summary /tmp/pr-summary.md
echo "exit_code=$?" >> $GITHUB_OUTPUT
- name: Check for translation changes
id: check_changes
run: |
if ! git diff --quiet; then
echo "has_changes=true" >> $GITHUB_OUTPUT
elif git ls-files --others --exclude-standard | grep -q "\.mdx$"; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No translation changes to commit."
fi
- name: Create branch and commit translations
id: create_branch
if: steps.check_changes.outputs.has_changes == 'true'
run: |
BRANCH="i18n/sync-${{ steps.commits.outputs.short_sha }}-$(date +%Y%m%d%H%M%S)"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH"
git add "ja/" "zh/" "snippets/ja/" "snippets/zh/" 2>/dev/null || true
git diff --cached --quiet || git commit -m "i18n: sync translations for ${{ steps.commits.outputs.short_sha }}"
git push origin "$BRANCH"
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
- name: Create Pull Request
if: steps.check_changes.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
SHORT_SHA="${{ steps.commits.outputs.short_sha }}"
AFTER="${{ steps.commits.outputs.after }}"
PR_NUMBER="${{ steps.commits.outputs.pr_number }}"
SUMMARY=$(cat /tmp/pr-summary.md 2>/dev/null || echo "See changed files for details.")
# Build reference line — link to original PR if available
if [ -n "$PR_NUMBER" ]; then
REF="Triggered by PR [#${PR_NUMBER}](https://github.com/${{ github.repository }}/pull/${PR_NUMBER}) (\`${SHORT_SHA}\`)"
else
REF="Triggered by [\`${SHORT_SHA}\`](https://github.com/${{ github.repository }}/commit/${AFTER})"
fi
# Ensure the 'translation' label exists (creates it if missing)
gh label create "translation" --color "0075ca" --description "Auto-generated translation PR" 2>/dev/null || true
gh pr create \
--title "[i18n] Sync translations for #${PR_NUMBER:-$SHORT_SHA}" \
--body "This PR was auto-generated by the translation sync workflow.
**${REF}**
${SUMMARY}
---
> ⚠️ Please review all translations carefully before merging.
> Sections marked \`[FALLBACK]\` in the commit log kept the original translation due to API or validation errors.
> To add a new language, add an entry to \`.github/scripts/translation-config.json\`." \
--base main \
--head "${{ steps.create_branch.outputs.branch }}" \
--label "translation"