Skip to content

updatemessages

updatemessages #5571

name: updatemessages
on:
schedule:
- cron: '0 0 * * *'
jobs:
updatemessages:
if: github.repository == 'DMOJ/online-judge'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.7
uses: actions/setup-python@v5
with:
python-version: '3.7'
- name: Checkout submodules
run: |
git submodule init
git submodule update
- name: Install requirements
run: |
sudo apt-get install gettext
wget https://artifacts.crowdin.com/repo/deb/crowdin3.deb -O crowdin.deb
sudo dpkg -i crowdin.deb
pip install -r requirements.txt
pip install pymysql
- name: Update English source strings
run: |
echo "STATIC_ROOT = '/tmp'" > dmoj/local_settings.py
python manage.py makemessages -l en -e py,html,txt
python manage.py makemessages -l en -d djangojs
- name: Download strings from Crowdin
env:
CROWDIN_API_TOKEN: ${{ secrets.CROWDIN_API_V2_TOKEN }}
run: |
cat > crowdin.yaml <<EOF
project_id: 142963
files:
- source: /locale/en/LC_MESSAGES/django.po
translation: /locale/%two_letters_code%/LC_MESSAGES/django.po
languages_mapping:
two_letters_code:
zh-CN: zh_Hans
zh-TW: zh_Hant
sr-CS: sr_Latn
- source: /locale/en/LC_MESSAGES/djangojs.po
translation: /locale/%two_letters_code%/LC_MESSAGES/djangojs.po
languages_mapping:
two_letters_code:
zh-CN: zh_Hans
zh-TW: zh_Hant
sr-CS: sr_Latn
EOF
echo "api_token: ${CROWDIN_API_TOKEN}" >> crowdin.yaml
crowdin download
rm crowdin.yaml
- name: Cleanup
run: |
rm -rf src/
git add locale
git checkout .
git clean -fd
git reset
- name: Remove useless changes
run: |
set -eu
i18n_head=$(git rev-parse --verify -q origin/update-i18n || echo "HEAD")
echo "Comparing against: $i18n_head"
changed=0
while IFS= read -r -d $'\0' file; do
if git diff -s --exit-code "$file"; then
continue
fi
if git diff "$i18n_head" -- "$file" | tail -n +5 2>/dev/null | grep -qP '^[-+](?!"PO-Revision-Date:|"POT-Creation-Date:)'; then
echo "Changed: $file"
changed=1
else
echo "No material change: $file"
git checkout "$i18n_head" -- "$file" > /dev/null 2>&1
fi
done < <(git ls-files -z 'locale/*/LC_MESSAGES/*.po')
if [ "$changed" = 0 ]; then
git reset --hard "$i18n_head"
fi
- name: Create pull request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.REPO_SCOPED_TOKEN }}
author: dmoj-build <build@dmoj.ca>
committer: dmoj-build <build@dmoj.ca>
commit-message: 'i18n: update translations from Crowdin'
title: Update translations from Crowdin
body: This PR has been auto-generated to pull in latest translations from [Crowdin](https://translate.dmoj.ca).
labels: i18n, enhancement
reviewers: Xyene, quantum5
branch: update-i18n