Skip to content

Crowdin Translations Sync #148

Crowdin Translations Sync

Crowdin Translations Sync #148

Workflow file for this run

name: Crowdin Translations Sync
on:
# Run on push to master to upload new source strings
push:
branches:
- master
paths:
- 'lib/l10n/app_*.arb'
# Run daily to download latest translations
schedule:
- cron: '0 0 * * *' # Daily at midnight UTC
# Allow manual trigger
workflow_dispatch:
jobs:
sync-crowdin:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# Push local translations to Crowdin first so GitHub edits are not lost
- name: Crowdin push (upload source + local translations)
uses: crowdin/github-action@v2
with:
upload_sources: true
upload_translations: true
download_translations: false
project_id: ${{ secrets.CROWDIN_PROJECT_ID }}
token: ${{ secrets.CROWDIN_API_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Crowdin pull (download translations)
id: crowdin_pull
uses: crowdin/github-action@v2
with:
upload_sources: false
upload_translations: false
download_translations: true
skip_untranslated_strings: true
export_only_approved: false
create_pull_request: false
project_id: ${{ secrets.CROWDIN_PROJECT_ID }}
token: ${{ secrets.CROWDIN_API_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Normalize ARB locales
run: |
for file in lib/l10n/app_*.arb; do
locale=$(basename "$file" .arb | sed 's/app_//')
sed -i "s/\"@@locale\": \"[^\"]*\"/\"@@locale\": \"$locale\"/g" "$file"
done
# Remove translation keys that do not exist in app_en.arb (orphaned keys)
- name: Cleanup extra translation keys
run: |
python3 << 'EOF'
import json
import glob
import os
en_path = 'lib/l10n/app_en.arb'
with open(en_path, 'r', encoding='utf-8') as f:
en_arb = json.load(f)
en_keys = set(en_arb.keys())
for filepath in glob.glob('lib/l10n/app_*.arb'):
if filepath.endswith('app_en.arb'):
continue
with open(filepath, 'r', encoding='utf-8') as f:
arb = json.load(f)
cleaned = {}
for key, value in arb.items():
if key == '@@locale' or key in en_keys:
cleaned[key] = value
if cleaned != arb:
with open(filepath, 'w', encoding='utf-8') as f:
json.dump(cleaned, f, ensure_ascii=False, indent=2)
f.write('\n')
print(f"Cleaned extra keys from {os.path.basename(filepath)}")
EOF
- name: Fix file permissions
run: sudo chown -R $USER:$USER .
- name: Check for translation changes
id: changes
run: |
git diff --quiet && echo "changed=false" >> "$GITHUB_OUTPUT" || echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Create Pull Request
if: steps.changes.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v6
id: cpr
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: update and normalize translations from Crowdin'
title: 'New Crowdin translations'
body: 'New translations from Crowdin with normalized @@locale entries to prevent build failures.'
branch: 'l10n_crowdin_action'
base: 'master'
# - name: Enable Pull Request Automerge
# if: steps.cpr.outputs.pull_request-number != ''
# run: gh pr merge "${{ steps.cpr.outputs.pull_request-number }}" --auto --merge
# env:
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}