bug 619097
[phpmyadmin/crack.git] / lang / sync_lang.sh
blobcce3cd79f83a6d3309fa1c1ec61a66300aa5c16e
1 #!/bin/sh
2 # $Id$
3 ##
4 # Shell script that synchronises all translations in phpMyAdmin
5 ##
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>
13 # Changes:
14 # 2002-09-18
15 # * now accepts parameters --iconv/--recode for specifying which convertor
16 # to use
17 # 2002-08-13
18 # * support for synchronisation only for selected language(s)
19 # 2002-07-18
20 # * can exclude some languages from conversion
21 # 2002-07-17
22 # * support for multiple convertors (recode added)
26 # convertor setup
28 # CONVERTOR_PARAMS is used for printf and it also receives two params: source
29 # and target charset
31 case "$1" in
32 --iconv)
33 echo Using iconv on user request
34 CONVERTOR=iconv
35 CONVERTOR_PARAMS="-f %s -t %s"
36 shift
38 --recode)
39 echo Using recode on user request
40 CONVERTOR=recode
41 CONVERTOR_PARAMS="%s..%s"
42 shift
45 echo Using recode as default, force with --iconv/--recode
46 CONVERTOR=recode
47 CONVERTOR_PARAMS="%s..%s"
49 esac
53 # names of translations to process
55 # Here should be listed all translations for which conversion should be done.
56 # The name is filename without inc.php3.
58 BASE_TRANSLATIONS=`cat <<EOT
59 afrikaans-iso-8859-1
60 albanian-iso-8859-1
61 arabic-windows-1256
62 brazilian_portuguese-iso-8859-1
63 bulgarian-koi8-r
64 catalan-iso-8859-1
65 chinese_big5
66 chinese_gb
67 croatian-iso-8859-2
68 czech-iso-8859-2
69 danish-iso-8859-1
70 dutch-iso-8859-1
71 english-iso-8859-1
72 estonian-iso-8859-1
73 finnish-iso-8859-1
74 french-iso-8859-1
75 galician-iso-8859-1
76 german-iso-8859-1
77 greek-iso-8859-7
78 hebrew-iso-8859-8-i
79 hungarian-iso-8859-2
80 indonesian-iso-8859-1
81 italian-iso-8859-1
82 japanese-euc
83 korean-ks_c_5601-1987
84 latvian-windows-1257
85 lithuanian-windows-1257
86 malay-iso-8859-1
87 norwegian-iso-8859-1
88 polish-iso-8859-2
89 portuguese-iso-8859-1
90 romanian-iso-8859-1
91 russian-windows-1251
92 serbian-windows-1250
93 slovenian-iso-8859-2
94 slovak-iso-8859-2
95 spanish-iso-8859-1
96 swedish-iso-8859-1
97 thai-tis-620
98 turkish-iso-8859-9
99 ukrainian-windows-1251
100 EOT`
103 # which translations should not be translated to utf-8
105 # List here any translation that should not be converted to utf-8. The name is
106 # same as above.
108 IGNORE_UTF=`cat <<EOT
109 hebrew-iso-8859-8-i
110 korean-ks_c_5601-1987
111 EOT`
114 # which translations should not be automatically generated
116 # List here any translation should not be automatically generated from base
117 # translation for that language (usually for those which are not correctly
118 # supported by convertor).
120 IGNORE_TRANSLATIONS=`cat <<EOT
121 japanese-sjis
122 russian-dos-866
123 EOT`
126 # end of configuration, you hopefully won't need to edit anything bellow
129 echo "-------------------------------------------------------------------"
130 # go through all file we should process
131 for base in $BASE_TRANSLATIONS ; do
132 if [ "$#" -gt 0 ] ; then
133 if ( echo $base | grep -q "$@" ) ; then
134 true
135 else
136 continue
139 # grep language from basename
140 lang=$(echo $base|sed 's%-.*%%')
141 # which files will we create from current?
142 create_files=$(ls --color=none -1 $lang*.inc.php3|grep -v $base.inc.php3)
144 for ignore in $IGNORE_TRANSLATIONS ; do
145 create_files=$(echo "$create_files" | grep -v $ignore)
146 done
148 # charset of source file
149 src_charset=$(grep '\$charset' $base.inc.php3 | sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")
150 echo "$base [charset $src_charset]"
152 is_utf=no
154 # at first update existing translations
155 for file in $create_files ; do
156 # charset of destination file
157 charset=$(grep '\$charset' $file | sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")
158 echo -n " to $charset..."
159 if [ $charset = 'utf-8' ] ; then
160 # if we convert to utf-8, we should add allow_recoding
161 is_utf=yes
162 $CONVERTOR $(printf -- "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php3| sed -e "s/$src_charset/$charset/" -e '/\$charset/a\
163 $allow_recoding = TRUE;' > $file
164 echo done
165 elif [ $src_charset = 'utf-8' ] ; then
166 # if we convert from utf-8, we should remove allow_recoding
167 $CONVERTOR $(printf -- "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php3| grep -v allow_recoding > $file
168 echo done
169 else
170 # just convert
171 $CONVERTOR $(printf -- "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php3| sed "s/$src_charset/$charset/" > $file
172 echo done
174 done
176 # now check whether we found utf-8 translation
177 if [ $is_utf = no ] ; then
178 if ( echo $IGNORE_UTF | grep -q $base ) ; then
179 # utf-8 should not be created
180 true
181 else
182 # we should create utf-8 translation
183 echo " creating utf-8 translation"
184 charset=utf-8
185 iconv -f $src_charset -t $charset $base.inc.php3| sed -e "s/$src_charset/$charset/" -e '/\$charset/a\
186 $allow_recoding = TRUE;' > $lang-$charset.inc.php3
189 echo "$lang processing finished."
190 echo "-------------------------------------------------------------------"
191 done