-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_ts.sh
executable file
·226 lines (187 loc) · 5.3 KB
/
update_ts.sh
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/env bash
###########################################################################
# update_ts.sh
# ---------------------
# Date : November 2014
# Copyright : (C) 2014 by Juergen E. Fischer
# Email : jef at norbit dot de
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
set -e
export SRCDIR=$PWD
retries=20
action=$1
case "$action" in
pull|push|update)
;;
*)
echo "usage: $(basename $0) {pull|{push|update} builddirectory [lang...]}"
exit 1
esac
cleanup() {
cd $SRCDIR
if [ -f i18n/backup.tar ]; then
echo Restoring files...
tar -xf i18n/backup.tar
rm i18n/backup.tar
fi
echo Removing temporary files
rm -rf python/tmp python/plugins/processing/tmp python/plugins/*/tmp qgis_ts.pro
find src python \( -name "*-i18n.ui" -o -name "*-i18n.cpp" -o -name "*-i18n.ts" \) -delete
trap "" EXIT
}
export QT_SELECT=5
PATH=$QTDIR/bin:$PATH
if type cygpath >/dev/null 2>&1; then
SRCDIR=$(cygpath -am $SRCDIR)
fi
if type qmake-qt5 >/dev/null 2>&1; then
QMAKE=qmake-qt5
else
QMAKE=qmake
fi
if ! type pylupdate5 >/dev/null 2>&1; then
echo "pylupdate5 not found"
exit 1
fi
if type lupdate-qt5 >/dev/null 2>&1; then
LUPDATE=lupdate-qt5
else
LUPDATE=lupdate
fi
if ! type tx >/dev/null 2>&1; then
echo "tx not found"
exit 1
fi
files=
if [ -d "$2" ]; then
builddir=$(realpath $2)
textcpp=
for i in $builddir/src/core/qgsexpression_texts.cpp $builddir/src/core/qgsexpressionparser.cpp; do
if [ -f $i ]; then
textcpp="$textcpp $i"
elif [ "$action" != "pull" ]; then
echo Generated help file $i not found
exit 1
fi
done
shift
shift
if [[ $# -gt 0 ]]; then
for t in i18n/qgis_*.ts; do
for l in "$@"; do
if [ "i18n/qgis_$l.ts" = "$t" ]; then
continue 2
fi
done
files="$files $t"
done
fi
elif [ "$action" != "pull" ]; then
echo Build directory not found
exit 1
else
shift
fi
trap cleanup EXIT
echo Saving translations
files="$files $(find python -name "*.ts")"
[ $action = push ] && files="$files i18n/qgis_*.ts"
[ -n "${files## }" ] && tar --remove-files -cf i18n/backup.tar $files
if [ $action = push ]; then
echo Pulling source from transifex...
fail=1
for i in $(seq $retries); do
tx pull -s && fail=0 && break
echo Retry $i/$retries...
sleep 10
done
if (( fail )) || ! [ -f "i18n/qgis_en.ts" ]; then
echo Download of source translation failed
exit 1
fi
cp i18n/qgis_en.ts /tmp/qgis_en.ts-downloaded
perl scripts/ts_clear.pl # reset English translations
elif [ $action = pull ]; then
mv i18n/qgis_en.ts i18n/qgis_en.ts.source
rm -f i18n/qgis_*.ts
mv i18n/qgis_en.ts.source i18n/qgis_en.ts
echo Pulling new translations...
if [ "$#" -gt 0 ]; then
o=$*
o="-l ${o// /,}"
else
o="-a"
fi
fail=1
for i in $(seq $retries); do
tx pull $o --minimum-perc=35 && fail=0 && break
echo Retry $i/$retries...
sleep 10
done
if (( fail )); then
echo "Could not pull translations"
exit 1
fi
fi
if [ -d "$builddir" ]; then
echo Updating python translations
(
cd python
mkdir -p tmp
pylupdate5 user.py utils.py {console,pyplugin_installer}/*.{py,ui} -ts python-i18n.ts
perl ../scripts/ts2ui.pl python-i18n.ts tmp
rm python-i18n.ts
)
for i in python/plugins/*/CMakeLists.txt; do
cd ${i%/*}
cat <<EOF >python-i18n.pro
SOURCES = $(find . -type f -name "*.py" -print | sed -e 's/^/ /' -e 's/$/ \\/')
FORMS = $(find . -type f -name "*.ui" -print | sed -e 's/^/ /' -e 's/$/ \\/')
TRANSLATIONS = python-i18n.ts
EOF
pylupdate5 -tr-function trAlgorithm python-i18n.pro
mkdir -p tmp
perl ../../../scripts/ts2ui.pl python-i18n.ts tmp
rm python-i18n.ts python-i18n.pro
cd ../../..
done
echo Updating GRASS module translations
perl scripts/qgm2ui.pl >src/plugins/grass/grasslabels-i18n.ui
echo Updating processing translations
mkdir -p python/plugins/processing/tmp
perl scripts/processing2ui.pl python/plugins/processing/tmp
echo Updating appinfo files
python3 scripts/appinfo2ui.py >src/app/appinfo-i18n.ui
echo Creating qmake project file
$QMAKE -project -o qgis_ts.pro -nopwd $SRCDIR/src $SRCDIR/python $SRCDIR/i18n $textcpp
QT_INSTALL_HEADERS=$(qmake -query QT_INSTALL_HEADERS)
echo "TR_EXCLUDE = ${QT_INSTALL_HEADERS%}/*" >>qgis_ts.pro
echo Updating translations
$LUPDATE -no-ui-lines -no-obsolete -locations absolute -verbose qgis_ts.pro
perl -i.bak -ne 'print unless /^\s+<location.*(qgs(expression|contexthelp)_texts\.cpp|-i18n\.(ui|cpp)).*$/;' i18n/qgis_*.ts
fi
if [ $action = push ]; then
cp i18n/qgis_en.ts /tmp/qgis_en.ts-uploading
echo Pushing translation...
fail=1
for i in $(seq $retries); do
tx push -s && fail=0 && break
echo Retry $i/$retries...
sleep 10
done
if (( fail )); then
echo "Could not push translations"
exit 1
fi
else
echo Updating TRANSLATORS File
./scripts/tsstat.pl >doc/TRANSLATORS
fi