Skip to content

Dispatch - Generate Transifex and Translatewiki translations #126

Dispatch - Generate Transifex and Translatewiki translations

Dispatch - Generate Transifex and Translatewiki translations #126

name: Dispatch - Generate Transifex and Translatewiki translations
on:
workflow_dispatch:
inputs:
theme_branch:
description: 'Theme Branch'
required: false
default: 'develop'
jobs:
generate-translations:
name: Detect changed source and generate Transifex and Translatewiki translations
runs-on: ubuntu-20.04
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install OS requirements
run: |
sudo apt-get update --fix-missing
sudo apt-get install pkg-config libxml2-dev libxmlsec1-dev libxmlsec1-openssl gettext
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash
- name: Check TX Version
run: |
export PATH="$PWD:$PATH"
tx --version
- name: Install pip requirements
run: |
python3 -m pip install pip==20.0.2
python3 -m pip install setuptools==60.9.3
python3 -m pip install wheel==0.37.1
pip install --disable-pip-version-check --exists-action w -r requirements/edx/development.txt
- name: Clone edx-theme repo
id: clone-theme-repo
uses: actions/checkout@v3
with:
repository: wikimedia/wikilearn-edx-theme
path: ./themes
ref: ${{ inputs.theme_branch }}
token: ${{ secrets.THEME_ACCESS_TOKEN }}
- name: Checkout master as feature branch does not exist
uses: actions/checkout@v3
with:
repository: wikimedia/wikilearn-edx-theme
path: ./themes
ref: master
token: ${{ secrets.THEME_ACCESS_TOKEN }}
if: steps.clone-theme-repo.outcome == 'failure'
- name: Pull latest translations from Transifex
id: pull-latest-translations-from-transifex
env:
TX_TOKEN: ${{ secrets.TX_TOKEN }}
TX_HOSTNAME: https://rest.api.transifex.com
run: |
export PATH="$PWD:$PATH"
export NO_PREREQ_INSTALL='true'
export LMS_CFG=$(pwd)/lms/devstack.yml
export STUDIO_CFG=$(pwd)/cms/devstack.yml
python manage.py cms translatewiki pull_transifex_translations
unset LMS_CFG
unset STUDIO_CFG
- name: Generate translations for changed source
id: generate-new-translations
env:
TX_TOKEN: ${{ secrets.TX_TOKEN }}
run: make extract_translations
- name: Merge all the translations
id: merge-translations-edx
run: |
export NO_PREREQ_INSTALL='true'
export LMS_CFG=$(pwd)/lms/devstack.yml
export STUDIO_CFG=$(pwd)/cms/devstack.yml
python manage.py cms translatewiki msgmerge
unset LMS_CFG
unset STUDIO_CFG
- name: Merge translations from translatewiki & manual files
id: merge-translations-translatewiki
run: |
export NO_PREREQ_INSTALL='true'
export LMS_CFG=$(pwd)/lms/devstack.yml
export STUDIO_CFG=$(pwd)/cms/devstack.yml
python manage.py cms translatewiki update_from_version
python manage.py cms translatewiki remove_bad_msgstr
unset LMS_CFG
unset STUDIO_CFG
- name: Delete qqq folder if exists
id: delete-qqq-files
run: rm -r conf/locale/qqq
continue-on-error: true
- name: generate i18n files
id: generate-i18n-files
run: |
paver i18n_fastgenerate
msgattrib --no-obsolete --set-fuzzy conf/locale/en/LC_MESSAGES/wm-django.po -o conf/locale/en/LC_MESSAGES/wm-django.po
msgattrib --no-obsolete --set-fuzzy conf/locale/en/LC_MESSAGES/wm-djangojs.po -o conf/locale/en/LC_MESSAGES/wm-djangojs.po
continue-on-error: true
- name: Check errors
run: |
export NO_PREREQ_INSTALL='true'
export LMS_CFG=$(pwd)/lms/devstack.yml
export STUDIO_CFG=$(pwd)/cms/devstack.yml
django-admin.py compilemessages
i18n_tool validate
unset LMS_CFG
unset STUDIO_CFG
exit 1
if: steps.generate-i18n-files.outcome != 'success'
- name: Compile JS translations
id: compile-js-i18n-files
run: |
export NO_PREREQ_INSTALL='true'
export LMS_CFG=$(pwd)/lms/devstack.yml
export STUDIO_CFG=$(pwd)/cms/devstack.yml
paver i18n_compilejs
unset LMS_CFG
unset STUDIO_CFG
- name: Genereate custom strings
id: generate-custom-strings
env:
TX_TOKEN: ${{ secrets.TX_TOKEN }}
TX_HOSTNAME: https://rest.api.transifex.com
run: |
export PATH="$PWD:$PATH"
export NO_PREREQ_INSTALL='true'
export LMS_CFG=$(pwd)/lms/devstack.yml
export STUDIO_CFG=$(pwd)/cms/devstack.yml
python manage.py cms translatewiki generate_custom_strings
unset LMS_CFG
unset STUDIO_CFG
- name: Restore qqq files
run: git restore conf/locale/qqq/
continue-on-error: true
- name: Create Pull Request and commit changed translation files
id: cpr
uses: peter-evans/create-pull-request@v4
with:
branch: 'gitflow/auto-generated-translations'
commit-message: 'Add changed translation files'
add-paths: |
conf/locale/**/LC_MESSAGES/wm-django.po
conf/locale/**/LC_MESSAGES/wm-djangojs.po
conf/locale/**/LC_MESSAGES/django.mo
conf/locale/**/LC_MESSAGES/django.po
conf/locale/**/LC_MESSAGES/djangojs.po
conf/locale/**/LC_MESSAGES/djangojs.mo
lms/static/js/i18n/**/djangojs.js
cms/static/js/i18n/**/djangojs.js
token: ${{ secrets.EDX_PLATFORM_ACCESS_TOKEN }}
signoff: true
delete-branch: true
- name: Auto Merge Changes
id: merge-changes
uses: peter-evans/enable-pull-request-automerge@v2
with:
token: ${{ secrets.EDX_PLATFORM_ACCESS_TOKEN }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: squash
if: steps.cpr.outputs.pull-request-operation == 'created'