lang
[phpmyadmin/crack.git] / lang / sync_lang.sh
blobf02c46e59b27fe89e7376b366364030e812ec78e
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
32 case "$1" in
33 --iconv)
34 echo Using iconv on user request
35 CONVERTOR=iconv
36 # the space on following is REQUIRED
37 CONVERTOR_PARAMS=" -f %s -t %s"
38 shift
40 --recode)
41 echo Using recode on user request
42 CONVERTOR=recode
43 CONVERTOR_PARAMS="%s..%s"
44 shift
47 echo Using recode as default, force with --iconv/--recode
48 CONVERTOR=recode
49 CONVERTOR_PARAMS="%s..%s"
51 esac
55 # names of translations to process
57 # Here should be listed all translations for which conversion should be done.
58 # The name is filename without inc.php3.
60 BASE_TRANSLATIONS=`cat <<EOT
61 afrikaans-iso-8859-1
62 albanian-iso-8859-1
63 arabic-windows-1256
64 brazilian_portuguese-iso-8859-1
65 bulgarian-koi8-r
66 catalan-iso-8859-1
67 chinese_big5
68 chinese_gb
69 croatian-iso-8859-2
70 czech-iso-8859-2
71 danish-iso-8859-1
72 dutch-iso-8859-1
73 english-iso-8859-1
74 estonian-iso-8859-1
75 farsi-windows-1256
76 finnish-iso-8859-1
77 french-iso-8859-1
78 galician-iso-8859-1
79 german-iso-8859-1
80 greek-iso-8859-7
81 hebrew-iso-8859-8-i
82 hungarian-iso-8859-2
83 indonesian-iso-8859-1
84 italian-iso-8859-1
85 japanese-euc
86 korean-ks_c_5601-1987
87 latvian-windows-1257
88 lithuanian-windows-1257
89 malay-iso-8859-1
90 norwegian-iso-8859-1
91 polish-iso-8859-2
92 portuguese-iso-8859-1
93 romanian-iso-8859-1
94 russian-windows-1251
95 serbian-windows-1250
96 slovenian-iso-8859-2
97 slovak-iso-8859-2
98 spanish-iso-8859-1
99 swedish-iso-8859-1
100 thai-tis-620
101 turkish-iso-8859-9
102 ukrainian-windows-1251
103 EOT`
106 # which translations should not be translated to utf-8
108 # List here any translation that should not be converted to utf-8. The name is
109 # same as above.
111 IGNORE_UTF=`cat <<EOT
112 hebrew-iso-8859-8-i
113 korean-ks_c_5601-1987
114 EOT`
117 # which translations should not be automatically generated
119 # List here any translation should not be automatically generated from base
120 # translation for that language (usually for those which are not correctly
121 # supported by convertor).
123 IGNORE_TRANSLATIONS=`cat <<EOT
124 japanese-sjis
125 russian-dos-866
126 EOT`
129 # end of configuration, you hopefully won't need to edit anything bellow
132 echo "-------------------------------------------------------------------"
133 # go through all file we should process
134 for base in $BASE_TRANSLATIONS ; do
135 if [ "$#" -gt 0 ] ; then
136 if ( echo $base | grep -q "$@" ) ; then
137 true
138 else
139 continue
142 # grep language from basename
143 lang=$(echo $base|sed 's%-.*%%')
144 # which files will we create from current?
145 create_files=$(ls --color=none -1 $lang*.inc.php3|grep -v $base.inc.php3)
147 for ignore in $IGNORE_TRANSLATIONS ; do
148 create_files=$(echo "$create_files" | grep -v $ignore)
149 done
151 # charset of source file
152 src_charset=$(grep '\$charset' $base.inc.php3 | sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")
153 echo "$base [charset $src_charset]"
155 is_utf=no
157 # at first update existing translations
158 for file in $create_files ; do
159 # charset of destination file
160 charset=$(grep '\$charset' $file | sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")
161 echo -n " to $charset..."
162 if [ $charset = 'utf-8' ] ; then
163 # if we convert to utf-8, we should add allow_recoding
164 is_utf=yes
165 $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php3| sed -e "s/$src_charset/$charset/" -e '/\$charset/a\
166 $allow_recoding = TRUE;' > $file
167 echo done
168 elif [ $src_charset = 'utf-8' ] ; then
169 # if we convert from utf-8, we should remove allow_recoding
170 $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php3| grep -v allow_recoding > $file
171 echo done
172 else
173 # just convert
174 $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php3| sed "s/$src_charset/$charset/" > $file
175 echo done
177 done
179 # now check whether we found utf-8 translation
180 if [ $is_utf = no ] ; then
181 if ( echo $IGNORE_UTF | grep -q $base ) ; then
182 # utf-8 should not be created
183 true
184 else
185 # we should create utf-8 translation
186 echo " creating utf-8 translation"
187 charset=utf-8
188 iconv -f $src_charset -t $charset $base.inc.php3| sed -e "s/$src_charset/$charset/" -e '/\$charset/a\
189 $allow_recoding = TRUE;' > $lang-$charset.inc.php3
192 echo "$lang processing finished."
193 echo "-------------------------------------------------------------------"
194 done