blob: b5504925f321678a173241d685e010bc3da031ad (
plain)
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
#!/bin/bash
# turn tracing on with /bin/bash -x
#
# Check for translation work by checking out / updating from SVN and
# displaying the project name when your language.po has fuzzy strings or
# empty string messages. Also useful for translation of web pages.
#
# Filip Komar, 2012, 2013
# Remco Rijnders, 2012
# $Id$
#
# Please see SVN for a list of changes to this script.
#
# More information about this script is in README file.
if [ -f ~/.mageia-i18n-config ]; then
source ~/.mageia-i18n-config
else
cat > ~/.mageia-i18n-config << "EOF"
# Please change the below values to match your needs:
language_code=xx
# Where to put the svn files and your working directory,
# please make sure those directories exist before running the script!!!
svn_directory="/home/user/Mageia/i18n/svn"
working_translations_directory="/home/user/Mageia/i18n/translations"
# choose svn method:
# 1. anonymous (no commit access)
svn_method="svn://"
# 2. public ssh key svn access. Remember to upload it to identity!
# Otherwise it will prompty you for password everytime for every resource.
#svn_method="svn+ssh://"
# The following lines can be changed if you desire, but this is
# not needed to properly use this script.
# set checking syntax of po files with 1
check_po_syntax=1
# set copying of po files with 1
copying_po=1
# set copying of web page files with 1
copying_wp=1
# uncomment next line to exclude checkout of software resources for mageia 2
#checkout_soft_mga2=no
# uncomment next line to exclude checkout of software resources for mageia 3
#checkout_soft_mga3=no
# ADVANCED SETTINGS
# set checking syntax of pot files with 1
check_pot_syntax=0
# set copying options (-i: interactive, -v: verbose, -u: update, -r: recursive)
copy_options="-ivur"
# choose log filename
log_filename="updated_translations_in_svn"
log_directory="$svn_directory"
logfile="$svn_directory/$log_filename"
# switch of logging by uncommenting the following line
#logfile="/dev/null"
# set checking of fuzzy and untranslated strings with 1
# WARNING: listings can be really long
check_fuzzy_and_untranslated=0
# checkout whole website www.mageia.org and mognase navigation
checkout_whole_website=0
# set searching for new *.pot files in svn with 1
searching_for_new_pot_files_in_svn=0
# whether to look for new versions of the script and project files
check_updates=1
# red color for differences from last time (green 32, blue 34)
color_for_differences=31
EOF
echo "This script has not been configured yet for you. A template"
echo "configuration file named .mageia-i18n-config has been made in your"
echo "home directory. Please edit it according to your needs and remember"
echo "to create apropriate directories before running this script again."
echo
echo "For more information about this script please read README file."
exit
fi
# save pwd to saved_dir
saved_dir=$(pwd)
if [ -f "$logfile"_this_run.log ]; then
mv "$logfile"_this_run.log "$logfile"_previous_run.log
fi
separator="-----------------------------------------------------"
# Check if both directories exist
if [ ! -d "$svn_directory" ]; then
mkdir -vp "$svn_directory/" | tee -a "$logfile"_this_run.log
fi
if [ ! -d "$working_translations_directory" ]; then
mkdir -vp "$working_translations_directory/" | tee -a "$logfile"_this_run.log
fi
echo "" | tee -a "$logfile"_this_run.log
echo "" | tee -a "$logfile"_this_run.log
date | tee -a "$logfile"_this_run.log
# Check if a newer version of this script is available. If yes, show the changes.
my_version=`echo "$Revision$" | cut -d" " -f2`
svn_version=`svn info svn://svn.mageia.org/svn/soft/i18n-tools/check_for_translation_work.sh | grep "Last Changed Rev:" | cut -c19-`
echo Revision: $my_version | tee -a "$logfile"_this_run.log
if [ $check_updates -eq 1 ]; then
if [ $my_version -lt $svn_version ]; then
echo "You are running revision $my_version of this script, while $svn_version is available on SVN."
echo "You may consider updating. Changes are:"
let "tmp=$my_version + 1"
svn log -r $tmp:$svn_version svn://svn.mageia.org/svn/soft/i18n-tools/check_for_translation_work.sh
fi
svn export --force svn://svn.mageia.org/svn/soft/i18n-tools/translation_projects.dat "$svn_directory"
echo ""
fi
declare -A projects
declare -A web_pages
source "$svn_directory/translation_projects.dat"
echo "SW files:" | tee -a "$logfile"_this_run.log
# echo about checking the syntax of po file if required
if [ $check_po_syntax -eq 1 ]; then
echo "Syntax of $language_code.po in svn will be tested."
fi
# echo about copying the *.pot file and $language_code.po for editing in apropriate directory if required
if [ $copying_po -eq 1 ]; then
echo "Files *.pot and $language_code.po will be copied into apropriate directory."
fi
for project_name in "${!projects[@]}"
do
echo $separator | tee -a "$logfile"_this_run.log
echo Working on: \'$project_name\' from \'${projects[$project_name]}\'. | tee -a "$logfile"_this_run.log
# Check out / update project files
if [ -d "$svn_directory/$project_name" ]; then
cd "$svn_directory/$project_name"
# just echo $language_code.po or *.pot file line if they are updated
svn up | grep -E "$language_code.po|[\.]pot" | tee -a "$logfile"_this_run.log
# echo -n "" # debug
else
cd "$svn_directory"
# just echo $language_code.po or *.pot file line if they are updated
svn co $svn_method${projects[$project_name]} $project_name | grep -E "$language_code.po|[\.]pot" | tee -a "$logfile"_this_run.log
# echo -n "" # debug
cd "$svn_directory/$project_name"
fi
# verbose checking for fuzzy and untranslated strings
if [ $check_fuzzy_and_untranslated -eq 1 ]; then
msgattrib $language_code.po --only-fuzzy --no-obsolete
msgattrib $language_code.po --untranslated --no-obsolete
fi
# checking the syntax of po file if required
if [ $check_po_syntax -eq 1 ]; then
if [ -f $language_code.po ]; then
msgfmt --statistics --verbose -c $language_code.po -o /dev/null 2>&1 | tee -a "$logfile"_this_run.log
else
echo "File $language_code.po is not present in $project_name. Automatic test is not possible." | tee -a "$logfile"_this_run.log
fi
# checking the syntax of po file if required
if [ $check_pot_syntax -eq 1 ]; then
if [ -f *.pot ]; then
msgfmt -c *.pot -o /dev/null 2>&1 | tee -a "$logfile"_this_run.log
else
echo "File *.pot is not present in $project_name. Automatic test is not possible." | tee -a "$logfile"_this_run.log
fi
fi
fi
# copying the *.pot file and $language_code.po for editing in working directory if required
if [ $copying_po -eq 1 ]; then
if [ ! -d "$working_translations_directory/$project_name/" ]; then
mkdir -vp "$working_translations_directory/$project_name/" | tee -a "$logfile"_this_run.log
fi
if [ -f $language_code.po ]; then
# testing for differences of *.po file from working copy
if [ -f "$working_translations_directory/$project_name/$language_code.po" ]; then
diff -q $language_code.po "$working_translations_directory/$project_name/$language_code.po" | tee -a "$logfile"_this_run.log
fi
cp $copy_options $language_code.po "$working_translations_directory/$project_name/" | tee -a "$logfile"_this_run.log
else
echo "File $language_code.po is not present in $project_name. Copying is not possible." | tee -a "$logfile"_this_run.log
fi
if [ -f *.pot ]; then
# testing for differences of *.pot file from working copy
if [ -f "$working_translations_directory/$project_name/"*.pot ]; then
diff -q *.pot "$working_translations_directory/$project_name/"*.pot | tee -a "$logfile"_this_run.log
fi
cp $copy_options *.pot "$working_translations_directory/$project_name/" | tee -a "$logfile"_this_run.log
# set -x # turn tracing on with set -x
cd "$working_translations_directory/$project_name/"
if [ -f *.pot_$language_code.po ]; then
# creating new_pot_lang.po from latest *.pot file
msgmerge -q *.pot_$language_code.po *.pot > new_pot_$language_code.po # msgmerge *.pot_lang.po *.pot > new_pot_lang.po
# comparing new_pot_lang.po from working copy
diff -q *.pot_$language_code.po new_pot_$language_code.po | tee -a "$logfile"_this_run.log
# diff -q $language_code.po new_pot_$language_code.po | tee -a "$logfile"_this_run.log
diff_exit_status_1=${PIPESTATUS[0]} # this reads and remembers exit status of first command in pipe (diff in this case)
# if [ $? -eq 0 ]; then
if [ $diff_exit_status_1 -eq 0 ]; then # no differences
rm new_pot_$language_code.po # remove resulting file
# echo Between *.pot_$language_code.po and new_pot_$language_code.po there are no differences.
else
if [ $diff_exit_status_1 -eq 1 ]; then # there are differences
echo Replace existing file *.pot_$language_code.po with new_pot_$language_code.po in $project_name since there are differences. | tee -a "$logfile"_this_run.log
else
echo There was an error in diff between *.pot_$language_code.po and new_pot_$language_code.po in $project_name.
fi
fi
# comparing svn lang.po from working copy lang.po
if [ -f $language_code.po ]; then
diff -q *.pot_$language_code.po $language_code.po | tee -a "$logfile"_this_run.log
diff_exit_status_2=${PIPESTATUS[0]} # this reads and remembers exit status of first command in pipe (diff in this case)
# if [ $? -eq 0 ]; then
if [ $diff_exit_status_2 -eq 1 ]; then # there are differences
echo New commit will be needed when the file *.pot_$language_code.po is ready in $project_name. | tee -a "$logfile"_this_run.log
else
if [ $diff_exit_status_2 -eq 2 ]; then # there was an error
echo There was an error in diff between file *.pot_$language_code.po and $language_code.po in $project_name.
fi
fi
fi
else
echo "File *.pot_$language_code.po is not present in $project_name. Comparing is not possible." | tee -a "$logfile"_this_run.log
fi
# set +x # turn tracing off with set +x
else
echo "File *.pot is not present in $project_name. Copying is not possible." | tee -a "$logfile"_this_run.log
fi
# echo "Files *.pot and $language_code.po copied into $working_translations_directory/$project_name/."
fi
cd "$svn_directory/"
echo "" | tee -a "$logfile"_this_run.log
done
# Check out / update web_page files
echo "web page files:" | tee -a "$logfile"_this_run.log
for web_page_name in "${!web_pages[@]}"
do
echo $separator | tee -a "$logfile"_this_run.log
echo Working on: "$web_page_name" from "${web_pages[$web_page_name]}". | tee -a "$logfile"_this_run.log # \'
# turn tracing on with set -x
# set -x
if [ -d "$svn_directory/$web_page_name/" ]; then
cd "$svn_directory/$web_page_name"
# just echo $language_code.lang or *.php file line if they are updated
svn up | grep -E "$language_code.lang|en.lang|[\.]php" | tee -a "$logfile"_this_run.log
# echo -n "" # debug
else
cd "$svn_directory/"
# just echo $language_code.lang or *.php file line if they are updated
svn co $svn_method${web_pages[$web_page_name]} $web_page_name | grep -E "$language_code.lang|en.lang|[\.]php" | tee -a "$logfile"_this_run.log
echo -n "" | tee -a "$logfile"_this_run.log
cd "$svn_directory/$web_page_name"
fi
echo "" | tee -a "$logfile"_this_run.log
done
#copying the english files and $language_code.lang files for editing in working directory if required
if [ $copying_wp -eq 1 ]; then
echo $separator | tee -a "$logfile"_this_run.log
echo "Web files will be copied (updated) into working translations directory."
cd "$svn_directory"
if [ ! -d "$working_translations_directory/web_pages_lang/en/" ]; then
mkdir -vp "$working_translations_directory/web_pages_lang/en/" | tee -a "$logfile"_this_run.log
fi
cp $copy_options ./web_pages_lang/en/* "$working_translations_directory/web_pages_lang/en/" | tee -a "$logfile"_this_run.log
if [ ! -d "$working_translations_directory/web_pages_lang/$language_code/" ]; then
mkdir -vp "$working_translations_directory/web_pages_lang/$language_code/" | tee -a "$logfile"_this_run.log
fi
cp $copy_options ./web_pages_lang/$language_code/* "$working_translations_directory/web_pages_lang/$language_code/" | tee -a "$logfile"_this_run.log
if [ ! -d "$working_translations_directory/web_page_navigation/" ]; then
mkdir -vp "$working_translations_directory/web_page_navigation/" | tee -a "$logfile"_this_run.log
fi
cp $copy_options ./web_page_navigation/en.lang "$working_translations_directory/web_page_navigation/" | tee -a "$logfile"_this_run.log
cp $copy_options ./web_page_navigation/$language_code.lang "$working_translations_directory/web_page_navigation/" | tee -a "$logfile"_this_run.log
fi
# turn tracing off with set +x
# set +x
if [ -d "$svn_directory/web_page_navigation/" ]; then
if [ -d "$svn_directory/web_page_navigation_2/" ]; then
diff -rq "$svn_directory/web_page_navigation" "$svn_directory/web_page_navigation_2" | grep -E ".lang" | tee -a "$logfile"_this_run.log
else
echo "Both navigation directories ($svn_directory/web_page_navigation and $svn_directory/web_page_navigation_2) are not present. Comparing is not possible." | tee -a "$logfile"_this_run.log
fi
else
echo "Both navigation directories ($svn_directory/web_page_navigation and $svn_directory/web_page_navigation_2) are not present. Comparing is not possible." | tee -a "$logfile"_this_run.log
fi
echo "" | tee -a "$logfile"_this_run.log
if [ $searching_for_new_pot_files_in_svn -eq 1 ]; then
echo $separator | tee -a "$logfile"_this_run.log
echo "Searching for new *.pot files in svn." | tee -a "$logfile"_this_run.log
if [ -f "$log_directory"/new_svn_list_of_pot_files ]; then
mv "$log_directory"/new_svn_list_of_pot_files "$log_directory"/old_svn_list_of_pot_files # -f
fi
svn list -R svn://svn.mageia.org/svn/soft/ > "$log_directory"/svn_list
cat "$log_directory"/svn_list | grep [\.]pot > "$log_directory"/new_svn_list_of_pot_files
# svn list -R svn://svn.mageia.org/svn/soft/ | grep [\.]pot > new_svn_list_of_pot_files
if [ -f "$log_directory"/old_svn_list_of_pot_files ]; then
diff new_svn_list_of_pot_files old_svn_list_of_pot_files | tee -a "$logfile"_this_run.log
if [ ${PIPESTATUS[0]} -eq 0 ]; then # this reads exit status of first command in pipe
echo "No new *.pot files found." | tee -a "$logfile"_this_run.log
fi
fi
echo "" | tee -a "$logfile"_this_run.log
fi
# append this_run_log to full_log
cat "$logfile"_this_run.log >> "$logfile"_full.log
echo "" | tee -a "$logfile".log
echo $separator | tee -a "$logfile".log
if [ -f "$logfile"_previous_run.log ]; then
# show only differences and log them
echo "Differences from last run:" | tee -a "$logfile".log
echo -e "\E["$color_for_differences"m"
diff "$logfile"_this_run.log "$logfile"_previous_run.log | tee -a "$logfile".log
echo -e "\E[m"
fi
# if you use this script by click it in GUI uncomment the next line
#read -p "Press any key to continue... " -n1 -s
# restore saved_dir
cd "$saved_dir"
pwd
|