4 # Shell script that synchronises all translations in phpMyAdmin
6 # Any parameters (except --iconv/--recode) will be passed to grep to filter
7 # processed translation, for example: './sync_lang.sh czech' will process only
8 # czech translation, './sync_lang.sh -e czech -e english' will process czech
9 # and english translations.
11 # Written by Michal Cihar <nijel at users.sourceforge.net>
15 # * less verbose output to allow quick overview
17 # * hack for multibyte chars, so that \'; at the end will not fool PHP
19 # * default to iconv, as it doesn't break things as recode does
23 # * switch php3 -> php
25 # * convert only files that are needed to convert (checks mtime), --force to
27 # * get charset from filename when reading from file failed
28 # * report failed translations at the end
30 # * now accepts parameters --iconv/--recode for specifying which convertor
33 # * support for synchronisation only for selected language(s)
35 # * can exclude some languages from conversion
37 # * support for multiple convertors (recode added)
43 # CONVERTOR_PARAMS is used for printf and it also receives two params: source
49 echo Using
iconv on user request
51 # the space on following is REQUIRED
52 CONVERTOR_PARAMS
=" -f %s -t %s"
56 echo Using
recode on user request
57 echo '(please use iconv for arabic)'
59 CONVERTOR_PARAMS
=" -f %s..%s"
63 echo Using
iconv as default
, force with
--iconv/--recode
65 # the space on following is REQUIRED
66 CONVERTOR_PARAMS
=" -f %s -t %s"
70 if [ "$1" = "--force" ] ; then
79 # names of translations to process
81 # Here should be listed all translations for which conversion should be done.
82 # The name is filename without inc.php.
84 BASE_TRANSLATIONS
="afrikaans-iso-8859-1
87 azerbaijani-iso-8859-9
89 belarusian_cyrillic-windows-1251
90 belarusian_latin-utf-8
92 brazilian_portuguese-iso-8859-1
95 chinese_traditional-utf-8
96 chinese_simplified-gb2312
110 indonesian-iso-8859-1
115 lithuanian-windows-1257
120 portuguese-iso-8859-1
123 serbian_cyrillic-windows-1251
124 serbian_latin-windows-1250
132 ukrainian-windows-1251"
135 # which translations should not be translated to utf-8
137 # List here any translation that should not be converted to utf-8. The name is
143 # which translations should not be automatically generated
145 # List here any translation should not be automatically generated from base
146 # translation for that language (usually for those which are not correctly
147 # supported by convertor).
149 IGNORE_TRANSLATIONS
="
153 # end of configuration, you hopefully won't need to edit anything bellow
156 TEMPFILE
=`mktemp /tmp/pma-sync-lang.XXXXXX`
162 trap cleanup INT ABRT TERM
166 echo "-------------------------------------------------------------------"
167 # go through all file we should process
168 for base
in $BASE_TRANSLATIONS ; do
169 if [ "$#" -gt 0 ] ; then
170 if ( echo $base |
grep -q "$@" ) ; then
176 # grep language from basename
177 lang
=$
(echo $base|
sed 's%-.*%%')
178 # which files will we create from current?
179 create_files
=$
(ls --color=none
-1 $lang*.inc.php|
grep -v $base.inc.php
)
181 for ignore
in $IGNORE_TRANSLATIONS ; do
182 create_files
=$
(echo "$create_files" |
grep -v $ignore)
185 # charset of source file
186 src_charset
=$
(grep '\$charset' $base.inc.php |
sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")
187 replace_charset
=$src_charset
188 # special case for hebrew
189 if [ $src_charset = 'iso-8859-8-i' ] ; then
190 src_charset
=iso-8859-8
192 echo -n "$base [charset $src_charset]"
194 # do we already have utf-8 translation?
195 if [ $src_charset = 'utf-8' ] ; then
201 # at first update existing translations
202 for file in $create_files ; do
203 # charset of destination file
205 # grepping from file causes problems when it is empty...
206 charset
=$
(grep '\$charset' $file |
sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")
207 if [ -z "$charset" ] ; then
208 charset
=$
(echo $file |
sed -e 's/^[^-]*-//' -e 's/\.inc\.php\?$//')
211 if [ $charset = 'utf-8' ] ; then
215 # check whether we need to update translation
216 if [ ! "$base.inc.php" -nt "$file" -a "$FORCE" -eq 0 -a -s "$file" ] ; then
217 echo -n " ($file:ok)"
221 echo -n " ($file:to $charset:"
222 if [ $charset = 'utf-8' ] ; then
223 # if we convert to utf-8, we should add allow_recoding
225 $CONVERTOR $
(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php|
sed -e "s/$replace_charset/$charset/" -e '/\$charset/a\
226 $allow_recoding = TRUE;' > $TEMPFILE
227 elif [ $src_charset = 'utf-8' ] ; then
229 # if we convert from utf-8, we should remove allow_recoding
230 $CONVERTOR $
(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php|
grep -v allow_recoding |
sed "s/$replace_charset/$charset/" > $TEMPFILE
233 $CONVERTOR $
(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php|
sed "s/$replace_charset/$charset/" > $TEMPFILE
235 if [ -s $TEMPFILE ] ; then
236 sed "s/\\\\';[[:space:]]*$/\\\\\\\\';/" $TEMPFILE > $file
239 FAILED
="$FAILED $file"
244 # now check whether we found utf-8 translation
245 if [ $is_utf = no
] ; then
246 if ( echo $IGNORE_UTF |
grep -q $base ) ; then
247 # utf-8 should not be created
250 # we should create utf-8 translation
252 file=$lang-$charset.inc.php
253 echo -n " [$file:$charset:"
254 $CONVERTOR $
(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php|
sed -e "s/$replace_charset/$charset/" -e '/\$charset/a\
255 $allow_recoding = TRUE;' > $TEMPFILE
256 if [ -s $TEMPFILE ] ; then
257 cat $TEMPFILE > $file
260 FAILED
="$FAILED $file"
268 echo "-------------------------------------------------------------------"
270 if [ -z "$FAILED" ] ; then
271 echo "Everything seems to went okay"
273 echo "!!!SOME CONVERSION FAILED!!!"
274 echo "Following file were NOT updated:"
278 echo "!!!SOME CONVERSION FAILED!!!"