Skip to content

Commit

Permalink
Add workflow to auto-import Weblate changes
Browse files Browse the repository at this point in the history
If the Weblate GitHub user opens a PR, this will import the Weblate translations in that PR into the prelude, then export them, then create a diff of the changes that is used to add a commit to the PR's branch containing those changes.

The export is done because Weblate just appends new translations to its YAML files, but they're otherwise sorted alphabetically and the export is a way of doing that.
  • Loading branch information
Ortham committed Jul 6, 2024
1 parent 0d3d845 commit d4a3e99
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/import-translations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Import translations from Weblate

on: [pull_request]

jobs:
import:
runs-on: ubuntu-20.04

# Only run if the pull request was opened by Weblate's GitHub bot user.
if: ${{ github.event.sender.id == 1607653 && github.event.pull_request.maintainer_can_modify == true }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m venv .venv
./.venv/bin/activate
pip install -r requirements.txt
- name: Run import translations script
run: python scripts/import-translations.py

- name: Run the export translations script
run: python scripts/export-translations.py

- name: Create patch containing changes
run: git diff > sync-translations.patch

- name: Record pull request head data
run: |
echo 'export PR_HEAD_URL="${{ github.event.pull_request.head.repo.clone_url }}"' > git_vars.sh
echo 'export PR_HEAD_REF="${{ github.event.pull_request.head.ref }}"' >> git_vars.sh
echo 'export COMMIT_MESSAGE="Import translations from Weblate"' >> git_vars.sh
- name: Upload data
uses: actions/upload-artifact@v4
with:
name: sync-translations-data
path: |
sync-translations.patch
git_vars.sh

0 comments on commit d4a3e99

Please sign in to comment.