-
Notifications
You must be signed in to change notification settings - Fork 75
100 lines (97 loc) · 3.27 KB
/
updatemessages.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: updatemessages
on:
schedule:
- cron: '0 0 * * *'
jobs:
updatemessages:
if: github.repository == 'DMOJ/online-judge'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: '3.7'
- name: Checkout submodules
run: |
git submodule init
git submodule update
- name: Install requirements
run: |
sudo apt-get install gettext
curl -O https://artifacts.crowdin.com/repo/deb/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_TOKEN }}
run: |
cat > crowdin.yaml <<EOF
project_identifier: dmoj
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_key: ${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@v4
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