-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathhandleAppTranslations.sh
More file actions
executable file
·185 lines (152 loc) · 5.69 KB
/
handleAppTranslations.sh
File metadata and controls
executable file
·185 lines (152 loc) · 5.69 KB
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
#!/bin/sh
# verbose and exit on error
set -xe
# import GPG keys
gpg --import /gpg/nextcloud-bot.public.asc
gpg --allow-secret-key-import --import /gpg/nextcloud-bot.asc
gpg --list-keys
# fetch git repo
git clone git@github.com:$1/$2 /app
if [ ! -f '/app/.tx/config' ]; then
echo "Missing transifex configuration file .tx/config"
exit 1
fi
APP_ID=$(grep -oE '<id>.*</id>' appinfo/info.xml | head --lines 1 | sed -E 's/<id>(.*)<\/id>/\1/')
RESOURCE_ID=$(grep -oE '\[o:nextcloud:p:nextcloud:r:.*\]' .tx/config | sed -E 's/\[o:nextcloud:p:nextcloud:r:(.*)\]/\1/')
SOURCE_FILE=$(grep -oE '^source_file\s*=\s*(.+)$' .tx/config | sed -E 's/source_file\s*=\s*(.+)/\1/')
if [ "$RESOURCE_ID" = "MYAPP" ]; then
echo "Invalid transifex configuration file .tx/config (translating MYAPP instead of real value)"
exit 2
fi
if [ "$RESOURCE_ID" = "talk_desktop" ]; then
# Desktop client has no appinfo/info.xml
APP_ID="talk_desktop"
fi
# TODO use build/l10nParseAppInfo.php to fetch app names for l10n
versions='main master stable31 stable30 stable29'
if [ -f '/app/.tx/backport' ]; then
versions="main master $(cat /app/.tx/backport)"
fi
# build POT files for all versions
mkdir stable-templates
for version in $versions
do
# skip if the branch doesn't exist
if git branch -r | egrep "^\W*origin/$version$" ; then
echo "Valid branch"
else
echo "Invalid branch"
continue
fi
git checkout $version
# Migrate the transifex config to the new client version
tx migrate
git add --force .tx/config
rm .tx/config_*
git commit -am "Fix(l10n): Update Transifex configuration" -s || true
git push
# build POT files
/translationtool.phar create-pot-files
cd translationfiles/templates/
for file in $(ls)
do
FILE_SAVE_VERSION=$(echo $version | sed -E 's/\//-/')
mv $file ../../stable-templates/$FILE_SAVE_VERSION.$RESOURCE_ID.pot
done
cd ../..
done
# merge POT files into one
for file in $(ls stable-templates/master.*)
do
name=$(echo $file | cut -b 25- )
msgcat --use-first stable-templates/*.$name > $SOURCE_FILE
done
# alternative merge of main branch
for file in $(ls stable-templates/main.*)
do
name=$(echo $file | cut -b 23- )
msgcat --use-first stable-templates/*.$name > $SOURCE_FILE
done
# remove intermediate POT files
rm -rf stable-templates
# push sources
tx push -s
# pull translations - force pull because a fresh clone has newer time stamps
tx pull -f -a --minimum-perc=5
# Copy back the po files from transifex resource id to app id
if [ "$RESOURCE_ID" = "$APP_ID" ] ; then
echo 'App id and transifex resource id are the same, not renaming po files …'
else
echo "App id [$APP_ID] and transifex resource id [$RESOURCE_ID] mismatch"
echo 'Renaming po files …'
for file in $(ls translationfiles)
do
if [ "$file" = 'templates' ]; then
continue;
fi
# Some special handling for apps where the resource name is reserved by transifex (transfer, analytics, ...)
# in that case the downloaded ".po" files already have the correct name, so we skip the renaming.
if [ -f translationfiles/$file/$RESOURCE_ID.po ]; then
mv translationfiles/$file/$RESOURCE_ID.po translationfiles/$file/$APP_ID.po
fi
done
fi
for version in $versions
do
# skip if the branch doesn't exist
if git branch -r | egrep "^\W*origin/$version$" ; then
echo "Valid branch"
else
echo "Invalid branch"
continue
fi
git checkout $version
# delete removed l10n files that are used for language detection (they will be recreated during the write)
rm -f l10n/*.js l10n/*.json
# build JS/JSON based on translations
/translationtool.phar convert-po-files
if [ -d tests ]; then
# remove tests/
rm -rf tests
git checkout -- tests/
fi
# create git commit and push it
git add l10n/*.js l10n/*.json
git commit -am "Fix(l10n): Update translations from Transifex" -s || true
git push origin $version
echo "done with $version"
done
# End of verbose mode
set +x
EXIT_CODE=0
# Confirm German translation does not have the false "don't translate" warning
if [ $(jq '.translations[]' l10n/de.json | grep 'Benötigt keine Übersetzung. Hier wird nur die formelle Übersetzung verwendet (de_DE).' | wc -l) -ne 0 ]; then
echo "German language file contains the 'Benötigt keine Übersetzung. Hier wird nur die formelle Übersetzung verwendet (de_DE).' hint." 1>&2
EXIT=3
fi
# Confirm English source does not contain the pipe character which breaks the Symfony Translation library
if [ $(jq '.translations | keys[]' l10n/en_GB.json | grep '|' | wc -l) -ne 0 ]; then
echo "English source contains the pipe character" 1>&2
EXIT=4
fi
# Confirm English source does not contain the unicode single quote character
if [ $(jq '.translations | keys[]' l10n/en_GB.json | grep -E '(´|’)' | wc -l) -ne 0 ]; then
echo "English source contains unicode single quote character, that should be replaced by normal single quotes" 1>&2
EXIT=4
fi
for file in $(ls l10n/*.json)
do
# Make sure only RTL languages contain such characters
if [ "$file" != "l10n/ar.json" -a "$file" != "l10n/fa.json" -a "$file" != "l10n/he.json" -a "$file" != "l10n/ps.json" -a "$file" != "l10n/ug.json" -a "$file" != "l10n/ur_PK.json" ]; then
if [ $(jq '.translations[]' $file | grep -E '(\x{061C}|\x{0623}|\x{200E}|\x{200F}|\x{202A}|\x{202B}|\x{202C}|\x{202D}|\x{202E}|\x{2066}|\x{2067}|\x{2068}|\x{2069}|\x{206C}|\x{206D})' | wc -l) -ne 0 ]; then
echo "$file contains a RTL limited characters in the translations" 1>&2
EXIT=5
fi
fi
# Confirm translations do not contain the pipe character which breaks the Symfony Translation library
if [ $(jq '.translations[]' $file | grep '|' | wc -l) -ne 0 ]; then
echo "$file contains the pipe character" 1>&2
EXIT=6
fi
done
exit $EXIT_CODE