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
117 macedonian_cyrillic-windows-1251
121 portuguese-iso-8859-1
124 serbian_cyrillic-utf-8
133 ukrainian-windows-1251"
136 # which translations should not be translated to utf-8
138 # List here any translation that should not be converted to utf-8. The name is
144 # which translations should not be automatically generated
146 # List here any translation should not be automatically generated from base
147 # translation for that language (usually for those which are not correctly
148 # supported by convertor).
150 IGNORE_TRANSLATIONS
="
154 # end of configuration, you hopefully won't need to edit anything bellow
157 TEMPFILE
=`mktemp /tmp/pma-sync-lang.XXXXXX`
163 trap cleanup INT ABRT TERM
167 echo "-------------------------------------------------------------------"
168 # go through all file we should process
169 for base
in $BASE_TRANSLATIONS ; do
170 if [ "$#" -gt 0 ] ; then
171 if ( echo $base |
grep -q "$@" ) ; then
177 # grep language from basename
178 lang
=$
(echo $base|
sed 's%-.*%%')
179 # which files will we create from current?
180 create_files
=$
(ls --color=none
-1 $lang*.inc.php|
grep -v $base.inc.php
)
182 for ignore
in $IGNORE_TRANSLATIONS ; do
183 create_files
=$
(echo "$create_files" |
grep -v $ignore)
186 # charset of source file
187 src_charset
=$
(grep '\$charset' $base.inc.php |
sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")
188 replace_charset
=$src_charset
189 # special case for hebrew
190 if [ $src_charset = 'iso-8859-8-i' ] ; then
191 src_charset
=iso-8859-8
193 echo -n "$base [charset $src_charset]"
195 # do we already have utf-8 translation?
196 if [ $src_charset = 'utf-8' ] ; then
202 # at first update existing translations
203 for file in $create_files ; do
204 # charset of destination file
206 # grepping from file causes problems when it is empty...
207 charset
=$
(grep '\$charset' $file |
sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")
208 if [ -z "$charset" ] ; then
209 charset
=$
(echo $file |
sed -e 's/^[^-]*-//' -e 's/\.inc\.php\?$//')
212 if [ $charset = 'utf-8' ] ; then
216 # check whether we need to update translation
217 if [ ! "$base.inc.php" -nt "$file" -a "$FORCE" -eq 0 -a -s "$file" ] ; then
218 echo -n " ($file:ok)"
222 echo -n " ($file:to $charset:"
223 if [ $charset = 'utf-8' ] ; then
224 # if we convert to utf-8, we should add allow_recoding
226 $CONVERTOR $
(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php|
sed -e "s/$replace_charset/$charset/" -e '/\$charset/a\
227 $allow_recoding = TRUE;' > $TEMPFILE
228 elif [ $src_charset = 'utf-8' ] ; then
230 # if we convert from utf-8, we should remove allow_recoding
231 $CONVERTOR $
(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php|
grep -v allow_recoding |
sed "s/$replace_charset/$charset/" > $TEMPFILE
234 $CONVERTOR $
(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php|
sed "s/$replace_charset/$charset/" > $TEMPFILE
236 if [ -s $TEMPFILE ] ; then
237 sed "s/\\\\';[[:space:]]\+$/\\\\\\\\';/" $TEMPFILE > $file
240 FAILED
="$FAILED $file"
245 # now check whether we found utf-8 translation
246 if [ $is_utf = no
] ; then
247 if ( echo $IGNORE_UTF |
grep -q $base ) ; then
248 # utf-8 should not be created
251 # we should create utf-8 translation
253 file=$lang-$charset.inc.php
254 echo -n " [$file:$charset:"
255 $CONVERTOR $
(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php|
sed -e "s/$replace_charset/$charset/" -e '/\$charset/a\
256 $allow_recoding = TRUE;' > $TEMPFILE
257 if [ -s $TEMPFILE ] ; then
258 cat $TEMPFILE > $file
261 FAILED
="$FAILED $file"
269 echo "-------------------------------------------------------------------"
271 if [ -z "$FAILED" ] ; then
272 echo "Everything seems to went okay"
274 echo "!!!SOME CONVERSION FAILED!!!"
275 echo "Following file were NOT updated:"
279 echo "!!!SOME CONVERSION FAILED!!!"