sorry, wrong version checked in
[phpmyadmin/arisferyanto.git] / libraries / select_lang.lib.php
blob9a4b258c88eb067fa2730e0e324d088c05a4fd2b
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * phpMyAdmin Language Loading File
8 */
10 /**
11 * Define the path to the translations directory and get some variables
12 * from system arrays if 'register_globals' is set to 'off'
14 $lang_path = './lang/';
17 /**
18 * All the supported languages have to be listed in the array below.
19 * 1. The key must be the "official" ISO 639 language code and, if required,
20 * the dialect code. It can also contain some informations about the
21 * charset (see the Russian case).
22 * 2. The first of the values associated to the key is used in a regular
23 * expression to find some keywords corresponding to the language inside two
24 * environment variables.
25 * These values contains:
26 * - the "official" ISO language code and, if required, the dialect code
27 * also ('bu' for Bulgarian, 'fr([-_][[:alpha:]]{2})?' for all French
28 * dialects, 'zh[-_]tw' for Chinese traditional...), the dialect has to
29 * be specified as first;
30 * - the '|' character (it means 'OR');
31 * - the full language name.
32 * 3. The second values associated to the key is the name of the file to load
33 * without the 'inc.php' extension.
34 * 4. The last values associated to the key is the language code as defined by
35 * the RFC1766.
37 * Beware that the sorting order (first values associated to keys by
38 * alphabetical reverse order in the array) is important: 'zh-tw' (chinese
39 * traditional) must be detected before 'zh' (chinese simplified) for
40 * example.
42 * When there are more than one charset for a language, we put the -utf-8
43 * last because we need the default charset to be non-utf-8 to avoid
44 * problems on MySQL < 4.1.x if AllowAnywhereRecoding is FALSE.
46 * For Russian, we put 1251 first, because MSIE does not accept 866
47 * and users would not see anything.
49 $available_languages = array(
50 'af-iso-8859-1' => array('af|afrikaans', 'afrikaans-iso-8859-1', 'af'),
51 'af-utf-8' => array('af|afrikaans', 'afrikaans-utf-8', 'af'),
52 'ar-win1256' => array('ar|arabic', 'arabic-windows-1256', 'ar'),
53 'ar-utf-8' => array('ar|arabic', 'arabic-utf-8', 'ar'),
54 'az-iso-8859-9' => array('az|azerbaijani', 'azerbaijani-iso-8859-9', 'az'),
55 'az-utf-8' => array('az|azerbaijani', 'azerbaijani-utf-8', 'az'),
57 'becyr-win1251' => array('be|belarusian', 'belarusian_cyrillic-windows-1251', 'be'),
58 'becyr-utf-8' => array('be|belarusian', 'belarusian_cyrillic-utf-8', 'be'),
59 'belat-utf-8' => array('be[-_]lat|belarusian latin', 'belarusian_latin-utf-8', 'be-lat'),
60 'bg-win1251' => array('bg|bulgarian', 'bulgarian-windows-1251', 'bg'),
61 'bg-koi8-r' => array('bg|bulgarian', 'bulgarian-koi8-r', 'bg'),
62 'bg-utf-8' => array('bg|bulgarian', 'bulgarian-utf-8', 'bg'),
63 'bs-win1250' => array('bs|bosnian', 'bosnian-windows-1250', 'bs'),
64 'bs-utf-8' => array('bs|bosnian', 'bosnian-utf-8', 'bs'),
65 'ca-iso-8859-1' => array('ca|catalan', 'catalan-iso-8859-1', 'ca'),
66 'ca-utf-8' => array('ca|catalan', 'catalan-utf-8', 'ca'),
67 'cs-iso-8859-2' => array('cs|czech', 'czech-iso-8859-2', 'cs'),
68 'cs-win1250' => array('cs|czech', 'czech-windows-1250', 'cs'),
69 'cs-utf-8' => array('cs|czech', 'czech-utf-8', 'cs'),
70 'da-iso-8859-1' => array('da|danish', 'danish-iso-8859-1', 'da'),
71 'da-utf-8' => array('da|danish', 'danish-utf-8', 'da'),
72 'de-iso-8859-1' => array('de|german', 'german-iso-8859-1', 'de'),
73 'de-iso-8859-15' => array('de|german', 'german-iso-8859-15', 'de'),
74 'de-utf-8' => array('de|german', 'german-utf-8', 'de'),
75 'el-iso-8859-7' => array('el|greek', 'greek-iso-8859-7', 'el'),
76 'el-utf-8' => array('el|greek', 'greek-utf-8', 'el'),
77 'en-iso-8859-1' => array('en|english', 'english-iso-8859-1', 'en'),
78 'en-iso-8859-15' => array('en|english', 'english-iso-8859-15', 'en'),
79 'en-utf-8' => array('en|english', 'english-utf-8', 'en'),
80 'es-iso-8859-1' => array('es|spanish', 'spanish-iso-8859-1', 'es'),
81 'es-iso-8859-15' => array('es|spanish', 'spanish-iso-8859-15', 'es'),
82 'es-utf-8' => array('es|spanish', 'spanish-utf-8', 'es'),
83 'et-iso-8859-1' => array('et|estonian', 'estonian-iso-8859-1', 'et'),
84 'et-utf-8' => array('et|estonian', 'estonian-utf-8', 'et'),
85 'eu-iso-8859-1' => array('eu|basque', 'basque-iso-8859-1', 'eu'),
86 'eu-utf-8' => array('eu|basque', 'basque-utf-8', 'eu'),
87 'fa-win1256' => array('fa|persian', 'persian-windows-1256', 'fa'),
88 'fa-utf-8' => array('fa|persian', 'persian-utf-8', 'fa'),
89 'fi-iso-8859-1' => array('fi|finnish', 'finnish-iso-8859-1', 'fi'),
90 'fi-iso-8859-15' => array('fi|finnish', 'finnish-iso-8859-15', 'fi'),
91 'fi-utf-8' => array('fi|finnish', 'finnish-utf-8', 'fi'),
92 'fr-iso-8859-1' => array('fr|french', 'french-iso-8859-1', 'fr'),
93 'fr-iso-8859-15' => array('fr|french', 'french-iso-8859-15', 'fr'),
94 'fr-utf-8' => array('fr|french', 'french-utf-8', 'fr'),
95 'gl-iso-8859-1' => array('gl|galician', 'galician-iso-8859-1', 'gl'),
96 'gl-utf-8' => array('gl|galician', 'galician-utf-8', 'gl'),
97 'he-iso-8859-8-i' => array('he|hebrew', 'hebrew-iso-8859-8-i', 'he'),
98 'he-utf-8' => array('he|hebrew', 'hebrew-utf-8', 'he'),
99 'hi-utf-8' => array('hi|hindi', 'hindi-utf-8', 'hi'),
100 'hr-win1250' => array('hr|croatian', 'croatian-windows-1250', 'hr'),
101 'hr-iso-8859-2' => array('hr|croatian', 'croatian-iso-8859-2', 'hr'),
102 'hr-utf-8' => array('hr|croatian', 'croatian-utf-8', 'hr'),
103 'hu-iso-8859-2' => array('hu|hungarian', 'hungarian-iso-8859-2', 'hu'),
104 'hu-utf-8' => array('hu|hungarian', 'hungarian-utf-8', 'hu'),
105 'id-iso-8859-1' => array('id|indonesian', 'indonesian-iso-8859-1', 'id'),
106 'id-utf-8' => array('id|indonesian', 'indonesian-utf-8', 'id'),
107 'it-iso-8859-1' => array('it|italian', 'italian-iso-8859-1', 'it'),
108 'it-iso-8859-15' => array('it|italian', 'italian-iso-8859-15', 'it'),
109 'it-utf-8' => array('it|italian', 'italian-utf-8', 'it'),
110 'ja-euc' => array('ja|japanese', 'japanese-euc', 'ja'),
111 'ja-sjis' => array('ja|japanese', 'japanese-sjis', 'ja'),
112 'ja-utf-8' => array('ja|japanese', 'japanese-utf-8', 'ja'),
113 'ko-euc-kr' => array('ko|korean', 'korean-euc-kr', 'ko'),
114 'ko-utf-8' => array('ko|korean', 'korean-utf-8', 'ko'),
115 'ka-utf-8' => array('ka|georgian', 'georgian-utf-8', 'ka'),
116 'lt-win1257' => array('lt|lithuanian', 'lithuanian-windows-1257', 'lt'),
117 'lt-utf-8' => array('lt|lithuanian', 'lithuanian-utf-8', 'lt'),
118 'lv-win1257' => array('lv|latvian', 'latvian-windows-1257', 'lv'),
119 'lv-utf-8' => array('lv|latvian', 'latvian-utf-8', 'lv'),
120 'mn-utf-8' => array('mn|mongolian', 'mongolian-utf-8', 'mn'),
121 'ms-iso-8859-1' => array('ms|malay', 'malay-iso-8859-1', 'ms'),
122 'ms-utf-8' => array('ms|malay', 'malay-utf-8', 'ms'),
123 'nl-iso-8859-1' => array('nl|dutch', 'dutch-iso-8859-1', 'nl'),
124 'nl-iso-8859-15' => array('nl|dutch', 'dutch-iso-8859-15', 'nl'),
125 'nl-utf-8' => array('nl|dutch', 'dutch-utf-8', 'nl'),
126 'no-iso-8859-1' => array('no|norwegian', 'norwegian-iso-8859-1', 'no'),
127 'no-utf-8' => array('no|norwegian', 'norwegian-utf-8', 'no'),
128 'pl-iso-8859-2' => array('pl|polish', 'polish-iso-8859-2', 'pl'),
129 'pl-win1250' => array('pl|polish', 'polish-windows-1250', 'pl'),
130 'pl-utf-8' => array('pl|polish', 'polish-utf-8', 'pl'),
131 'ptbr-iso-8859-1' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-iso-8859-1', 'pt-BR'),
132 'ptbr-utf-8' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-utf-8', 'pt-BR'),
133 'pt-iso-8859-1' => array('pt|portuguese', 'portuguese-iso-8859-1', 'pt'),
134 'pt-iso-8859-15' => array('pt|portuguese', 'portuguese-iso-8859-15', 'pt'),
135 'pt-utf-8' => array('pt|portuguese', 'portuguese-utf-8', 'pt'),
136 'ro-iso-8859-1' => array('ro|romanian', 'romanian-iso-8859-1', 'ro'),
137 'ro-utf-8' => array('ro|romanian', 'romanian-utf-8', 'ro'),
138 'ru-win1251' => array('ru|russian', 'russian-windows-1251', 'ru'),
139 'ru-cp-866' => array('ru|russian', 'russian-cp-866', 'ru'),
140 'ru-koi8-r' => array('ru|russian', 'russian-koi8-r', 'ru'),
141 'ru-utf-8' => array('ru|russian', 'russian-utf-8', 'ru'),
142 'sk-iso-8859-2' => array('sk|slovak', 'slovak-iso-8859-2', 'sk'),
143 'sk-win1250' => array('sk|slovak', 'slovak-windows-1250', 'sk'),
144 'sk-utf-8' => array('sk|slovak', 'slovak-utf-8', 'sk'),
145 'sl-iso-8859-2' => array('sl|slovenian', 'slovenian-iso-8859-2', 'sl'),
146 'sl-win1250' => array('sl|slovenian', 'slovenian-windows-1250', 'sl'),
147 'sl-utf-8' => array('sl|slovenian', 'slovenian-utf-8', 'sl'),
148 'sq-iso-8859-1' => array('sq|albanian', 'albanian-iso-8859-1', 'sq'),
149 'sq-utf-8' => array('sq|albanian', 'albanian-utf-8', 'sq'),
150 'srlat-win1250' => array('sr[-_]lat|serbian latin', 'serbian_latin-windows-1250', 'sr-lat'),
151 'srlat-utf-8' => array('sr[-_]lat|serbian latin', 'serbian_latin-utf-8', 'sr-lat'),
152 'srcyr-win1251' => array('sr|serbian', 'serbian_cyrillic-windows-1251', 'sr'),
153 'srcyr-utf-8' => array('sr|serbian', 'serbian_cyrillic-utf-8', 'sr'),
154 'sv-iso-8859-1' => array('sv|swedish', 'swedish-iso-8859-1', 'sv'),
155 'sv-utf-8' => array('sv|swedish', 'swedish-utf-8', 'sv'),
156 'th-tis-620' => array('th|thai', 'thai-tis-620', 'th'),
157 'th-utf-8' => array('th|thai', 'thai-utf-8', 'th'),
158 'tr-iso-8859-9' => array('tr|turkish', 'turkish-iso-8859-9', 'tr'),
159 'tr-utf-8' => array('tr|turkish', 'turkish-utf-8', 'tr'),
160 'tt-iso-8859-9' => array('tt|tatarish', 'tatarish-iso-8859-9', 'tt'),
161 'tt-utf-8' => array('tt|tatarish', 'tatarish-utf-8', 'tt'),
162 'uk-win1251' => array('uk|ukrainian', 'ukrainian-windows-1251', 'uk'),
163 'uk-utf-8' => array('uk|ukrainian', 'ukrainian-utf-8', 'uk'),
164 'zhtw-big5' => array('zh[-_](tw|hk)|chinese traditional', 'chinese_traditional-big5', 'zh-TW'),
165 'zhtw-utf-8' => array('zh[-_](tw|hk)|chinese traditional', 'chinese_traditional-utf-8', 'zh-TW'),
166 'zh-gb2312' => array('zh|chinese simplified', 'chinese_simplified-gb2312', 'zh'),
167 'zh-utf-8' => array('zh|chinese simplified', 'chinese_simplified-utf-8', 'zh')
170 // Language filtering support
171 if (!empty($GLOBALS['cfg']['FilterLanguages'])) {
172 $new_lang = array();
173 foreach($available_languages as $key => $val) {
174 if (preg_match('@' . $GLOBALS['cfg']['FilterLanguages'] . '@', $key)) {
175 $new_lang[$key] = $val;
178 if (count($new_lang) > 0) {
179 $available_languages = $new_lang;
181 unset( $key, $val, $new_lang );
185 * Analyzes some PHP environment variables to find the most probable language
186 * that should be used
188 * @param string string to analyze
189 * @param integer type of the PHP environment variable which value is $str
191 * @global array the list of available translations
192 * @global string the retained translation keyword
194 * @access private
196 function PMA_langDetect($str = '', $envType = '')
198 global $available_languages;
199 global $lang;
201 foreach ($available_languages AS $key => $value) {
202 // $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable,
203 // 2 for the 'HTTP_USER_AGENT' one
204 $expr = $value[0];
205 if (strpos($expr, '[-_]') === FALSE) {
206 $expr = str_replace('|', '([-_][[:alpha:]]{2,3})?|', $expr);
208 if (($envType == 1 && eregi('^(' . $expr . ')(;q=[0-9]\\.[0-9])?$', $str))
209 || ($envType == 2 && eregi('(\(|\[|;[[:space:]])(' . $expr . ')(;|\]|\))', $str))) {
210 $lang = $key;
211 break;
214 } // end of the 'PMA_langDetect()' function
217 if (!isset($lang)) {
218 if (isset($_GET) && !empty($_GET['lang'])) {
219 $lang = $_GET['lang'];
221 else if (isset($_POST) && !empty($_POST['lang'])) {
222 $lang = $_POST['lang'];
224 else if (isset($_COOKIE) && !empty($_COOKIE['pma_lang'])) {
225 $lang = $_COOKIE['pma_lang'];
231 * Do the work!
234 // compatibility with config.inc.php <= v1.80
235 if (!isset($cfg['Lang']) && isset($cfgLang)) {
236 $cfg['Lang'] = $cfgLang;
237 unset($cfgLang);
239 if (!isset($cfg['DefaultLang']) && isset($cfgDefaultLang)) {
240 $cfg['DefaultLang'] = $cfgDefaultLang;
241 unset($cfgLang);
244 // MySQL charsets map
245 $mysql_charset_map = array(
246 'big5' => 'big5',
247 'cp-866' => 'cp866',
248 'euc-jp' => 'ujis',
249 'euc-kr' => 'euckr',
250 'gb2312' => 'gb2312',
251 'gbk' => 'gbk',
252 'iso-8859-1' => 'latin1',
253 'iso-8859-2' => 'latin2',
254 'iso-8859-7' => 'greek',
255 'iso-8859-8' => 'hebrew',
256 'iso-8859-8-i' => 'hebrew',
257 'iso-8859-9' => 'latin5',
258 'iso-8859-13' => 'latin7',
259 'iso-8859-15' => 'latin1',
260 'koi8-r' => 'koi8r',
261 'shift_jis' => 'sjis',
262 'tis-620' => 'tis620',
263 'utf-8' => 'utf8',
264 'windows-1250' => 'cp1250',
265 'windows-1251' => 'cp1251',
266 'windows-1252' => 'latin1',
267 'windows-1256' => 'cp1256',
268 'windows-1257' => 'cp1257',
271 // Lang forced
272 if (!empty($cfg['Lang'])) {
273 $lang = $cfg['Lang'];
276 // If '$lang' is defined, ensure this is a valid translation
277 if (!empty($lang) && empty($available_languages[$lang])) {
278 $lang = '';
281 // Language is not defined yet :
282 // 1. try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE
283 // variable
284 if (empty($lang) && !empty($HTTP_ACCEPT_LANGUAGE)) {
285 $accepted = explode(',', $HTTP_ACCEPT_LANGUAGE);
286 $acceptedCnt = count($accepted);
287 for ($i = 0; $i < $acceptedCnt && empty($lang); $i++) {
288 PMA_langDetect($accepted[$i], 1);
291 // 2. try to findout user's language by checking its HTTP_USER_AGENT variable
292 if (empty($lang) && !empty($HTTP_USER_AGENT)) {
293 PMA_langDetect($HTTP_USER_AGENT, 2);
296 // 3. Didn't catch any valid lang : we use the default settings
297 if (empty($lang)) {
298 $lang = $cfg['DefaultLang'];
301 // 4. Checks whether charset recoding should be allowed or not
302 $allow_recoding = FALSE; // Default fallback value
303 if (!isset($convcharset) || empty($convcharset)) {
304 if (isset($_COOKIE['pma_charset'])) {
305 $convcharset = $_COOKIE['pma_charset'];
306 } else {
307 $convcharset = $cfg['DefaultCharset'];
311 // 5. Defines the associated filename and load the translation
312 $lang_file = $lang_path . $available_languages[$lang][1] . '.inc.php';
313 require_once( $lang_file );
314 unset( $lang_file, $lang_path );