-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathhandleAppTranslations.sh
More file actions
executable file
·212 lines (171 loc) · 5.76 KB
/
handleAppTranslations.sh
File metadata and controls
executable file
·212 lines (171 loc) · 5.76 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
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
#!/bin/sh
# verbose and exit on error
set -xe
# Print tooling information
php -v
tx -v
xgettext -V
# 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/default --depth 1
cd default
if [ ! -f '.tx/config' ]; then
echo "Missing transifex configuration file .tx/config"
exit 1
fi
##################################
# 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
##################################
# Validate sync setup
##################################
DAY_OF_WEEK=$(date "+%w")
RESOURCE_ID=$(grep -oE '\[o:nextcloud:p:nextcloud:r:.*\]' .tx/config | sed -E 's/\[o:nextcloud:p:nextcloud:r:(.*)\]/\1/')
if [ "$RESOURCE_ID" = "talk_desktop" ]; then
echo "Skipping release check of Talk Desktop"
elif [ $DAY_OF_WEEK -eq 6 ]; then
APP_MAX_VERSION=$(grep -oE '<nextcloud.*max-version=".*".*>' appinfo/info.xml | head --lines 1 | sed -E 's/(.*)max-version="(.*)"(.*)/\2/')
if [ ! $APP_MAX_VERSION ]; then
echo "App has no max-version defined"
grep '<nextcloud' appinfo/info.xml | head --lines 1
exit 1
elif [ $APP_MAX_VERSION -lt 31 ]; then
echo "App was not released in the last year and translations should be stopped"
echo "Defined max-version is $APP_MAX_VERSION"
exit 1
fi
echo "App has max-version $APP_MAX_VERSION"
fi
APP_ID=$(grep -oE '<id>.*</id>' appinfo/info.xml | head --lines 1 | sed -E 's/<id>(.*)<\/id>/\1/')
IS_EX_APP=$(grep -q '<external-app>' appinfo/info.xml && grep -q '</external-app>' appinfo/info.xml && echo "true" || echo "false")
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
versions='main master stable33 stable32'
if [ -f '.tx/backport' ]; then
versions="main master $(cat .tx/backport)"
fi
mkdir stable-templates
mkdir -p translationfiles/templates/
##################################
# Clone backport branches
##################################
# Don't fail on checking out non existing branches
set +e
for version in $versions
do
git clone git@github.com:$1/$2 /app/$version --depth 1 --branch $version
done
set -e
##################################
# Build POT files for all versions
##################################
for version in $versions
do
if [ ! -d /app/$version ]; then
# skip if the branch doesn't exist
continue
fi
cd /app/$version
# 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 /app/default/stable-templates/$FILE_SAVE_VERSION.$RESOURCE_ID.pot
done
cd ../..
done
##################################
# Sync with transifex
##################################
cd /app/default
# 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
# delete removed l10n files that are used for language detection (they will be recreated during the write)
rm -f l10n/*.js l10n/*.json
# 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
# build JS/JSON based on translations
/translationtool.phar convert-po-files
##################################
# Add translations to branches again
##################################
for version in $versions
do
if [ ! -d /app/$version ]; then
# skip if the branch doesn't exist
continue
fi
cd /app/$version
# delete removed l10n files that are used for language detection (they will be recreated during the write)
rm -f l10n/*.js l10n/*.json
# Copy JS and JSON
cp /app/default/l10n/*.js /app/default/l10n/*.json l10n
# create git commit and push it
git add l10n/*.js l10n/*.json
# for ExApps, we need to include .po translation files as well
if [ "$IS_EX_APP" = "true" ]; then
cp /app/default/translationfiles/*.po translationfiles
git add translationfiles/*.po
fi
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 +xe
##################################
# Validate translations
##################################
if [ -f '.tx/validate' ]; then
/validateTranslationFiles.sh /app/default
fi
exit $?