bug 782828
[phpmyadmin/crack.git] / libraries / select_lang.lib.php3
blob8cb5186e4d220100a39b146b360c71940121130a
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * phpMyAdmin Language Loading File
8 */
12 if (!defined('PMA_SELECT_LANG_LIB_INCLUDED')) {
13 define('PMA_SELECT_LANG_LIB_INCLUDED', 1);
15 /**
16 * Define the path to the translations directory and get some variables
17 * from system arrays if 'register_globals' is set to 'off'
19 $lang_path = 'lang/';
22 /**
23 * All the supported languages have to be listed in the array below.
24 * 1. The key must be the "official" ISO 639 language code and, if required,
25 * the dialect code. It can also contain some informations about the
26 * charset (see the Russian case).
27 * 2. The first of the values associated to the key is used in a regular
28 * expression to find some keywords corresponding to the language inside two
29 * environment variables.
30 * These values contains:
31 * - the "official" ISO language code and, if required, the dialect code
32 * also ('bu' for Bulgarian, 'fr([-_][[:alpha:]]{2})?' for all French
33 * dialects, 'zh[-_]tw' for Chinese traditional...);
34 * - the '|' character (it means 'OR');
35 * - the full language name.
36 * 3. The second values associated to the key is the name of the file to load
37 * without the 'inc.php3' extension.
38 * 4. The last values associated to the key is the language code as defined by
39 * the RFC1766.
41 * Beware that the sorting order (first values associated to keys by
42 * alphabetical reverse order in the array) is important: 'zh-tw' (chinese
43 * traditional) must be detected before 'zh' (chinese simplified) for
44 * example.
46 * When there are more than one charset for a language, we put the -utf-8
47 * first.
49 * For Russian, we put 1251 first, because MSIE does not accept 866
50 * and users would not see anything.
52 $available_languages = array(
53 'af-utf-8' => array('af|afrikaans', 'afrikaans-utf-8', 'af'),
54 'af-iso-8859-1'=> array('af|afrikaans', 'afrikaans-iso-8859-1', 'af'),
55 'ar-utf-8' => array('ar([-_][[:alpha:]]{2})?|arabic', 'arabic-utf-8', 'ar'),
56 'ar-win1256' => array('ar([-_][[:alpha:]]{2})?|arabic', 'arabic-windows-1256', 'ar'),
57 'bg-utf-8' => array('bg|bulgarian', 'bulgarian-utf-8', 'bg'),
58 'bg-win1251' => array('bg|bulgarian', 'bulgarian-windows-1251', 'bg'),
59 'bg-koi8-r' => array('bg|bulgarian', 'bulgarian-koi8-r', 'bg'),
60 'ca-utf-8' => array('ca|catalan', 'catalan-utf-8', 'ca'),
61 'ca-iso-8859-1'=> array('ca|catalan', 'catalan-iso-8859-1', 'ca'),
62 'cs-utf-8' => array('cs|czech', 'czech-utf-8', 'cs'),
63 'cs-iso-8859-2'=> array('cs|czech', 'czech-iso-8859-2', 'cs'),
64 'cs-win1250' => array('cs|czech', 'czech-windows-1250', 'cs'),
65 'da-utf-8' => array('da|danish', 'danish-utf-8', 'da'),
66 'da-iso-8859-1'=> array('da|danish', 'danish-iso-8859-1', 'da'),
67 'de-utf-8' => array('de([-_][[:alpha:]]{2})?|german', 'german-utf-8', 'de'),
68 'de-iso-8859-1'=> array('de([-_][[:alpha:]]{2})?|german', 'german-iso-8859-1', 'de'),
69 'el-utf-8' => array('el|greek', 'greek-utf-8', 'el'),
70 'el-iso-8859-7'=> array('el|greek', 'greek-iso-8859-7', 'el'),
71 'en-utf-8' => array('en([-_][[:alpha:]]{2})?|english', 'english-utf-8', 'en'),
72 'en-iso-8859-1'=> array('en([-_][[:alpha:]]{2})?|english', 'english-iso-8859-1', 'en'),
73 'es-utf-8' => array('es([-_][[:alpha:]]{2})?|spanish', 'spanish-utf-8', 'es'),
74 'es-iso-8859-1'=> array('es([-_][[:alpha:]]{2})?|spanish', 'spanish-iso-8859-1', 'es'),
75 'et-utf-8' => array('et|estonian', 'estonian-utf-8', 'et'),
76 'et-iso-8859-1'=> array('et|estonian', 'estonian-iso-8859-1', 'et'),
77 'fi-utf-8' => array('fi|finnish', 'finnish-utf-8', 'fi'),
78 'fi-iso-8859-1'=> array('fi|finnish', 'finnish-iso-8859-1', 'fi'),
79 'fr-utf-8' => array('fr([-_][[:alpha:]]{2})?|french', 'french-utf-8', 'fr'),
80 'fr-iso-8859-1'=> array('fr([-_][[:alpha:]]{2})?|french', 'french-iso-8859-1', 'fr'),
81 'gl-utf-8' => array('gl|galician', 'galician-utf-8', 'gl'),
82 'gl-iso-8859-1'=> array('gl|galician', 'galician-iso-8859-1', 'gl'),
83 'he-iso-8859-8-i'=> array('he|hebrew', 'hebrew-iso-8859-8-i', 'he'),
84 'hi-utf-8' => array('hi|hindi', 'hindi-utf-8', 'hi'),
85 'hr-utf-8' => array('hr|croatian', 'croatian-utf-8', 'hr'),
86 'hr-win1250' => array('hr|croatian', 'croatian-windows-1250', 'hr'),
87 'hr-iso-8859-2'=> array('hr|croatian', 'croatian-iso-8859-2', 'hr'),
88 'hu-utf-8' => array('hu|hungarian', 'hungarian-utf-8', 'hu'),
89 'hu-iso-8859-2'=> array('hu|hungarian', 'hungarian-iso-8859-2', 'hu'),
90 'id-utf-8' => array('id|indonesian', 'indonesian-utf-8', 'id'),
91 'id-iso-8859-1'=> array('id|indonesian', 'indonesian-iso-8859-1', 'id'),
92 'it-utf-8' => array('it|italian', 'italian-utf-8', 'it'),
93 'it-iso-8859-1'=> array('it|italian', 'italian-iso-8859-1', 'it'),
94 'ja-utf-8' => array('ja|japanese', 'japanese-utf-8', 'ja'),
95 'ja-euc' => array('ja|japanese', 'japanese-euc', 'ja'),
96 'ja-sjis' => array('ja|japanese', 'japanese-sjis', 'ja'),
97 'ko-ks_c_5601-1987'=> array('ko|korean', 'korean-ks_c_5601-1987', 'ko'),
98 'ka-utf-8' => array('ka|georgian', 'georgian-utf-8', 'ka'),
99 'lt-utf-8' => array('lt|lithuanian', 'lithuanian-utf-8', 'lt'),
100 'lt-win1257' => array('lt|lithuanian', 'lithuanian-windows-1257', 'lt'),
101 'lv-utf-8' => array('lv|latvian', 'latvian-utf-8', 'lv'),
102 'lv-win1257' => array('lv|latvian', 'latvian-windows-1257', 'lv'),
103 'ms-utf-8' => array('ms|malay', 'malay-utf-8', 'ms'),
104 'ms-iso-8859-1'=> array('ms|malay', 'malay-iso-8859-1', 'ms'),
105 'nl-utf-8' => array('nl([-_][[:alpha:]]{2})?|dutch', 'dutch-utf-8', 'nl'),
106 'nl-iso-8859-1'=> array('nl([-_][[:alpha:]]{2})?|dutch', 'dutch-iso-8859-1', 'nl'),
107 'no-utf-8' => array('no|norwegian', 'norwegian-utf-8', 'no'),
108 'no-iso-8859-1'=> array('no|norwegian', 'norwegian-iso-8859-1', 'no'),
109 'pl-utf-8' => array('pl|polish', 'polish-utf-8', 'pl'),
110 'pl-iso-8859-2'=> array('pl|polish', 'polish-iso-8859-2', 'pl'),
111 'pt-br-utf-8' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-utf-8', 'pt-BR'),
112 'pt-br-iso-8859-1' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-iso-8859-1', 'pt-BR'),
113 'pt-utf-8' => array('pt([-_][[:alpha:]]{2})?|portuguese', 'portuguese-utf-8', 'pt'),
114 'pt-iso-8859-1'=> array('pt([-_][[:alpha:]]{2})?|portuguese', 'portuguese-iso-8859-1', 'pt'),
115 'ro-utf-8' => array('ro|romanian', 'romanian-utf-8', 'ro'),
116 'ro-iso-8859-1'=> array('ro|romanian', 'romanian-iso-8859-1', 'ro'),
117 'ru-win1251' => array('ru|russian', 'russian-windows-1251', 'ru'),
118 'ru-utf-8' => array('ru|russian', 'russian-utf-8', 'ru'),
119 'ru-dos-866' => array('ru|russian', 'russian-dos-866', 'ru'),
120 'ru-koi8-r' => array('ru|russian', 'russian-koi8-r', 'ru'),
121 'sk-utf-8' => array('sk|slovak', 'slovak-utf-8', 'sk'),
122 'sk-iso-8859-2'=> array('sk|slovak', 'slovak-iso-8859-2', 'sk'),
123 'sk-win1250' => array('sk|slovak', 'slovak-windows-1250', 'sk'),
124 'sl-utf-8' => array('sl|slovenian', 'slovenian-utf-8', 'sl'),
125 'sl-iso-8859-2'=> array('sl|slovenian', 'slovenian-iso-8859-2', 'sl'),
126 'sl-win1250' => array('sl|slovenian', 'slovenian-windows-1250', 'sl'),
127 'sq-utf-8' => array('sq|albanian', 'albanian-utf-8', 'sq'),
128 'sq-iso-8859-1'=> array('sq|albanian', 'albanian-iso-8859-1', 'sq'),
129 'sr-utf-8' => array('sr|serbian', 'serbian_cyrillic-utf-8', 'sr'),
130 'sr-win1251' => array('sr|serbian', 'serbian_cyrillic-windows-1251', 'sr'),
131 'sr-sh-utf-8' => array('sr[-_]sh|serbian latin', 'serbian_latin-utf-8', 'sr-sh'),
132 'sr-sh-win1250'=> array('sr[-_]sh|serbian latin', 'serbian_latin-windows-1250', 'sr-sh'),
133 'pt-br-iso-8859-1' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-iso-8859-1', 'pt-BR'),
134 'sv-utf-8' => array('sv|swedish', 'swedish-utf-8', 'sv'),
135 'sv-iso-8859-1'=> array('sv|swedish', 'swedish-iso-8859-1', 'sv'),
136 'th-utf-8' => array('th|thai', 'thai-utf-8', 'th'),
137 'th-tis-620' => array('th|thai', 'thai-tis-620', 'th'),
138 'tr-utf-8' => array('tr|turkish', 'turkish-utf-8', 'tr'),
139 'tr-iso-8859-9'=> array('tr|turkish', 'turkish-iso-8859-9', 'tr'),
140 'uk-utf-8' => array('uk|ukrainian', 'ukrainian-utf-8', 'uk'),
141 'uk-win1251' => array('uk|ukrainian', 'ukrainian-windows-1251', 'uk'),
142 'zh-tw-utf-8' => array('zh[-_]tw|chinese traditional', 'chinese_big5-utf-8', 'zh-TW'),
143 'zh-tw' => array('zh[-_]tw|chinese traditional', 'chinese_big5', 'zh-TW'),
144 'zh-utf-8' => array('zh|chinese simplified', 'chinese_gb-utf-8', 'zh'),
145 'zh' => array('zh|chinese simplified', 'chinese_gb', 'zh')
149 if (!defined('PMA_IS_LANG_DETECT_FUNCTION')) {
150 define('PMA_IS_LANG_DETECT_FUNCTION', 1);
153 * Analyzes some PHP environment variables to find the most probable language
154 * that should be used
156 * @param string string to analyze
157 * @param integer type of the PHP environment variable which value is $str
159 * @global array the list of available translations
160 * @global string the retained translation keyword
162 * @access private
164 function PMA_langDetect($str = '', $envType = '')
166 global $available_languages;
167 global $lang;
169 reset($available_languages);
170 while (list($key, $value) = each($available_languages)) {
171 // $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable,
172 // 2 for the 'HTTP_USER_AGENT' one
173 if (($envType == 1 && eregi('^(' . $value[0] . ')(;q=[0-9]\\.[0-9])?$', $str))
174 || ($envType == 2 && eregi('(\(|\[|;[[:space:]])(' . $value[0] . ')(;|\]|\))', $str))) {
175 $lang = $key;
176 break;
179 } // end of the 'PMA_langDetect()' function
181 } // end if
185 * Get some global variables if 'register_globals' is set to 'off'
186 * loic1 - 2001/25/11: use the new globals arrays defined with php 4.1+
188 if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
189 $HTTP_ACCEPT_LANGUAGE = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
191 else if (!empty($HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE'])) {
192 $HTTP_ACCEPT_LANGUAGE = $HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE'];
195 if (!empty($_SERVER['HTTP_USER_AGENT'])) {
196 $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
198 else if (!empty($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) {
199 $HTTP_USER_AGENT = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
202 if (!isset($lang)) {
203 if (isset($_GET) && !empty($_GET['lang'])) {
204 $lang = $_GET['lang'];
206 else if (isset($HTTP_GET_VARS) && !empty($HTTP_GET_VARS['lang'])) {
207 $lang = $HTTP_GET_VARS['lang'];
209 else if (isset($_POST) && !empty($_POST['lang'])) {
210 $lang = $_POST['lang'];
212 else if (isset($HTTP_POST_VARS) && !empty($HTTP_POST_VARS['lang'])) {
213 $lang = $HTTP_POST_VARS['lang'];
215 else if (isset($_COOKIE) && !empty($_COOKIE['lang'])) {
216 $lang = $_COOKIE['lang'];
218 else if (isset($HTTP_COOKIE_VARS) && !empty($HTTP_COOKIE_VARS['lang'])) {
219 $lang = $HTTP_COOKIE_VARS['lang'];
225 * Do the work!
228 // compatibility with config.inc.php3 <= v1.80
229 if (!isset($cfg['Lang']) && isset($cfgLang)) {
230 $cfg['Lang'] = $cfgLang;
231 unset($cfgLang);
233 if (!isset($cfg['DefaultLang']) && isset($cfgDefaultLang)) {
234 $cfg['DefaultLang'] = $cfgDefaultLang;
235 unset($cfgLang);
238 // Disable UTF-8 if $cfg['AllowAnywhereRecoding'] has been set to FALSE.
239 if (!isset($cfg['AllowAnywhereRecoding']) || !$cfg['AllowAnywhereRecoding']) {
240 $available_language_files = $available_languages;
241 $available_languages = array();
242 while (list($tmp_lang, $tmp_lang_data) = each($available_language_files)) {
243 if (substr($tmp_lang, -5) != 'utf-8') {
244 $available_languages[$tmp_lang] = $tmp_lang_data;
246 } // end while
247 unset($tmp_lang);
248 unset($tmp_lang_data);
249 unset($available_language_files);
250 } // end if
252 // Lang forced
253 if (!empty($cfg['Lang'])) {
254 $lang = $cfg['Lang'];
257 // If '$lang' is defined, ensure this is a valid translation
258 if (!empty($lang) && empty($available_languages[$lang])) {
259 $lang = '';
262 // Language is not defined yet :
263 // 1. try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE
264 // variable
265 if (empty($lang) && !empty($HTTP_ACCEPT_LANGUAGE)) {
266 $accepted = explode(',', $HTTP_ACCEPT_LANGUAGE);
267 $acceptedCnt = count($accepted);
268 reset($accepted);
269 for ($i = 0; $i < $acceptedCnt && empty($lang); $i++) {
270 PMA_langDetect($accepted[$i], 1);
273 // 2. try to findout user's language by checking its HTTP_USER_AGENT variable
274 if (empty($lang) && !empty($HTTP_USER_AGENT)) {
275 PMA_langDetect($HTTP_USER_AGENT, 2);
278 // 3. Didn't catch any valid lang : we use the default settings
279 if (empty($lang)) {
280 $lang = $cfg['DefaultLang'];
283 // 4. Checks whether charset recoding should be allowed or not
284 $allow_recoding = FALSE; // Default fallback value
285 if (!isset($convcharset) || empty($convcharset)) {
286 $convcharset = $cfg['DefaultCharset'];
289 // 5. Defines the associated filename and load the translation
290 $lang_file = $lang_path . $available_languages[$lang][1] . '.inc.php3';
291 include('./' . $lang_file);
293 } // $__PMA_SELECT_LANG_LIB__