Skip to content

i18n: sync Simplified Chinese content #5

i18n: sync Simplified Chinese content

i18n: sync Simplified Chinese content #5

Workflow file for this run

name: Content Translation
# Temporarily disabled until content translations are ready
# on:
# pull_request:
# types: [closed]
# branches:
# - master
# paths:
# - 'messages/en/*.json'
# - 'src/app/content/challenges/*/en/*.mdx'
# - 'src/app/content/challenges/*/en/pages/*.mdx'
# - 'src/app/content/courses/*/*/en.mdx'
concurrency:
group: translation-${{ github.ref }}
cancel-in-progress: false
jobs:
check_changes:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.check.outputs.has_changes }}
locales: ${{ steps.check.outputs.locales }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 2
- name: Check for translatable changes
id: check
timeout-minutes: 5
run: |
set -euxo pipefail
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
ALL_CHANGED=$(git diff --diff-filter=AM --name-only "$BASE_SHA" "$HEAD_SHA")
FILTERED_FILES=""
for file in $ALL_CHANGED; do
case "$file" in
messages/en/*.json|\
src/app/content/challenges/*/en/*.mdx|\
src/app/content/challenges/*/en/pages/*.mdx|\
src/app/content/courses/*/*/en.mdx)
FILTERED_FILES="$FILTERED_FILES $file"
;;
esac
done
if [ -z "$FILTERED_FILES" ]; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No translatable files changed."
else
echo "has_changes=true" >> $GITHUB_OUTPUT
LOCALES=$(cat i18n.json | jq -r '.locale.targets | @json')
echo "locales=$LOCALES" >> $GITHUB_OUTPUT
echo "Translatable files changed: $FILTERED_FILES"
fi
translate:
needs: check_changes
if: needs.check_changes.outputs.has_changes == 'true'
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
strategy:
matrix:
locale: ${{ fromJson(needs.check_changes.outputs.locales) }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: '24'
- name: Cache npx packages
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npx-lingodev-${{ hashFiles('.github/workflows/i18n.yaml') }}
restore-keys: |
${{ runner.os }}-npx-lingodev-
- name: Run translation
timeout-minutes: 10
env:
LINGODOTDEV_API_KEY: ${{ secrets.LINGODOTDEV_API_KEY }}
run: npx [email protected] i18n --locale ${{ matrix.locale }}
- name: Create Pull Request
timeout-minutes: 5
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_TITLE: "${{ github.event.pull_request.title }}"
PR_BRANCH: "${{ github.event.pull_request.head.ref }}"
LOCALE: ${{ matrix.locale }}
run: |
set -euxo pipefail
LANG_NAME=$(node .github/scripts/get-lang-name.js "$LOCALE")
NEW_BRANCH_NAME="translate-$PR_BRANCH-$LOCALE-${{ github.run_id }}"
if ! git status --porcelain | grep -q .; then
echo "No changes to commit for locale $LOCALE"
exit 0
fi
if ! gh label list | grep -q "^translation"; then
gh label create "translation" --description "Translation related changes" --color "0e8a16"
fi
if ! gh label list | grep -q "^help wanted"; then
gh label create "help wanted" --description "Extra attention is needed" --color "008672"
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b "$NEW_BRANCH_NAME"
git add .
git commit -m "feat(i18n): add $LANG_NAME translation for '$PR_TITLE'"
git push -u origin "$NEW_BRANCH_NAME"
gh pr create \
--title "$LANG_NAME Translation for: $PR_TITLE" \
--body "Automated translation to $LANG_NAME for changes in PR #${{ github.event.pull_request.number }}." \
--base master \
--head "$NEW_BRANCH_NAME" \
--label "translation" \
--label "help wanted"