-
Notifications
You must be signed in to change notification settings - Fork 192
147 lines (128 loc) · 4.53 KB
/
i18n.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Update Translations
on:
push:
paths:
- 'install.sh'
- 'fail2ban_manager.sh'
- 'file_manager.sh'
- 'translate.py'
branches:
- main
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
update-translations:
runs-on: ubuntu-latest
steps:
- name: Check running workflows
uses: styfle/cancel-workflow-action@0.12.1
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v4
with:
persist-credentials: true
- name: Restore translation cache
id: cache-translations
uses: actions/cache@v3
with:
path: po/cache_*.json
key: ${{ runner.os }}-translations-${{ hashFiles('po/*.po') }}
restore-keys: |
${{ runner.os }}-translations-
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y gettext python3 python3-pip i18nspector
pip3 install googletrans-py langdetect openai
- name: Cache Python dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-googletrans-py-langdetect-openai
restore-keys: |
${{ runner.os }}-pip-
- name: Setup directories
run: |
mkdir -p po
mkdir -p languages/{en,fa,ru,zh_CN,ko}/LC_MESSAGES
- name: Extract strings from specified scripts
run: |
echo "install.sh" > po/POTFILES.in
echo "fail2ban_manager.sh" >> po/POTFILES.in
echo "file_manager.sh" >> po/POTFILES.in
xgettext \
--files-from=po/POTFILES.in \
--from-code=UTF-8 \
--language=Shell \
--keyword=gettext \
--package-name=xray_install \
--package-version=1.0 \
--msgid-bugs-address=https://github.com/hello-yunshu/Xray_bash_onekey/issues \
--copyright-holder="yunshu" \
--output=po/xray_install.pot
- name: Update/Create PO files
run: |
rm -f po/*.po
for lang in zh_CN en fa ru ko; do
msginit --no-translator --locale=$lang --input=po/xray_install.pot --output=po/$lang.po
done
- name: Auto translate
run: python3 translate.py
env:
AI_API_KEY: ${{ secrets.AI_API_KEY }}
- name: Compile MO files if necessary
run: |
needs_compile=false
for lang in en fa ru ko; do
if [ ! -f "po/${lang}.po.no-update" ]; then
needs_compile=true
if ! msgfmt --check -v --statistics -o languages/${lang}/LC_MESSAGES/xray_install.mo po/${lang}.po; then
echo "Error in ${lang}.po file:"
cat po/${lang}.po
fi
fi
done
if [ "$needs_compile" = false ]; then
echo "No translations were updated. Skipping MO file compilation."
fi
- name: Run i18nspector checks on PO files
run: |
i18nspector check po/
- name: Run i18nspector checks on MO files if compiled
run: |
for lang in en fa ru ko; do
if [ ! -f "po/${lang}.po.no-update" ] && [ -f "languages/${lang}/LC_MESSAGES/xray_install.mo" ]; then
i18nspector check-binary languages/${lang}/LC_MESSAGES/xray_install.mo
fi
done
- name: Save translation cache
if: always()
uses: actions/cache@v3
with:
path: po/cache_*.json
key: ${{ runner.os }}-translations-${{ hashFiles('po/*.po') }}
- name: Pull changes
run: |
git pull origin main
- name: Commit changes if necessary
run: |
needs_commit=false
for lang in en fa ru ko; do
if [ ! -f "po/${lang}.po.no-update" ]; then
needs_commit=true
break
else
rm po/${lang}.po.no-update
fi
done
if [ "$needs_commit" = true ]; then
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add po/ languages/
git commit -m "Update translations for all languages [$(date +%Y-%m-%d)]" || echo "No changes to commit"
git push
else
echo "No translations were updated. Skipping commit and push."
fi