update
[phpmyadmin/crack.git] / libraries / select_lang.lib.php3
blobf4507d589bca4b156bc62403b325f9e6e4cdd790
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 $available_languages = array(
50 'af-utf-8' => array('af|afrikaans', 'afrikaans-utf-8', 'af'),
51 'af-iso-8859-1'=> array('af|afrikaans', 'afrikaans-iso-8859-1', 'af'),
52 'ar-utf-8' => array('ar([-_][[:alpha:]]{2})?|arabic', 'arabic-utf-8', 'ar'),
53 'ar-win1256' => array('ar([-_][[:alpha:]]{2})?|arabic', 'arabic-windows-1256', 'ar'),
54 'bg-utf-8' => array('bg|bulgarian', 'bulgarian-utf-8', 'bg'),
55 'bg-win1251' => array('bg|bulgarian', 'bulgarian-windows-1251', 'bg'),
56 'bg-koi8-r' => array('bg|bulgarian', 'bulgarian-koi8-r', 'bg'),
57 'ca-utf-8' => array('ca|catalan', 'catalan-utf-8', 'ca'),
58 'ca-iso-8859-1'=> array('ca|catalan', 'catalan-iso-8859-1', 'ca'),
59 'cs-utf-8' => array('cs|czech', 'czech-utf-8', 'cs'),
60 'cs-iso-8859-2'=> array('cs|czech', 'czech-iso-8859-2', 'cs'),
61 'cs-win1250' => array('cs|czech', 'czech-windows-1250', 'cs'),
62 'da-utf-8' => array('da|danish', 'danish-utf-8', 'da'),
63 'da-iso-8859-1'=> array('da|danish', 'danish-iso-8859-1', 'da'),
64 'de-utf-8' => array('de([-_][[:alpha:]]{2})?|german', 'german-utf-8', 'de'),
65 'de-iso-8859-1'=> array('de([-_][[:alpha:]]{2})?|german', 'german-iso-8859-1', 'de'),
66 'el-utf-8' => array('el|greek', 'greek-utf-8', 'el'),
67 'el-iso-8859-7'=> array('el|greek', 'greek-iso-8859-7', 'el'),
68 'en-utf-8' => array('en([-_][[:alpha:]]{2})?|english', 'english-utf-8', 'en'),
69 'en-iso-8859-1'=> array('en([-_][[:alpha:]]{2})?|english', 'english-iso-8859-1', 'en'),
70 'es-utf-8' => array('es([-_][[:alpha:]]{2})?|spanish', 'spanish-utf-8', 'es'),
71 'es-iso-8859-1'=> array('es([-_][[:alpha:]]{2})?|spanish', 'spanish-iso-8859-1', 'es'),
72 'et-utf-8' => array('et|estonian', 'estonian-utf-8', 'et'),
73 'et-iso-8859-1'=> array('et|estonian', 'estonian-iso-8859-1', 'et'),
74 'fi-utf-8' => array('fi|finnish', 'finnish-utf-8', 'fi'),
75 'fi-iso-8859-1'=> array('fi|finnish', 'finnish-iso-8859-1', 'fi'),
76 'fr-utf-8' => array('fr([-_][[:alpha:]]{2})?|french', 'french-utf-8', 'fr'),
77 'fr-iso-8859-1'=> array('fr([-_][[:alpha:]]{2})?|french', 'french-iso-8859-1', 'fr'),
78 'gl-utf-8' => array('gl|galician', 'galician-utf-8', 'gl'),
79 'gl-iso-8859-1'=> array('gl|galician', 'galician-iso-8859-1', 'gl'),
80 'he-iso-8859-8-i'=> array('he|hebrew', 'hebrew-iso-8859-8-i', 'he'),
81 'hi-utf-8' => array('hi|hindi', 'hindi-utf-8', 'hi'),
82 'hr-utf-8' => array('hr|croatian', 'croatian-utf-8', 'hr'),
83 'hr-win1250' => array('hr|croatian', 'croatian-windows-1250', 'hr'),
84 'hr-iso-8859-2'=> array('hr|croatian', 'croatian-iso-8859-2', 'hr'),
85 'hu-utf-8' => array('hu|hungarian', 'hungarian-utf-8', 'hu'),
86 'hu-iso-8859-2'=> array('hu|hungarian', 'hungarian-iso-8859-2', 'hu'),
87 'id-utf-8' => array('id|indonesian', 'indonesian-utf-8', 'id'),
88 'id-iso-8859-1'=> array('id|indonesian', 'indonesian-iso-8859-1', 'id'),
89 'it-utf-8' => array('it|italian', 'italian-utf-8', 'it'),
90 'it-iso-8859-1'=> array('it|italian', 'italian-iso-8859-1', 'it'),
91 'ja-utf-8' => array('ja|japanese', 'japanese-utf-8', 'ja'),
92 'ja-euc' => array('ja|japanese', 'japanese-euc', 'ja'),
93 'ja-sjis' => array('ja|japanese', 'japanese-sjis', 'ja'),
94 'ko-ks_c_5601-1987'=> array('ko|korean', 'korean-ks_c_5601-1987', 'ko'),
95 'ka-utf-8' => array('ka|georgian', 'georgian-utf-8', 'ka'),
96 'lt-utf-8' => array('lt|lithuanian', 'lithuanian-utf-8', 'lt'),
97 'lt-win1257' => array('lt|lithuanian', 'lithuanian-windows-1257', 'lt'),
98 'lv-utf-8' => array('lv|latvian', 'latvian-utf-8', 'lv'),
99 'lv-win1257' => array('lv|latvian', 'latvian-windows-1257', 'lv'),
100 'ms-utf-8' => array('ms|malay', 'malay-utf-8', 'ms'),
101 'ms-iso-8859-1'=> array('ms|malay', 'malay-iso-8859-1', 'ms'),
102 'nl-utf-8' => array('nl([-_][[:alpha:]]{2})?|dutch', 'dutch-utf-8', 'nl'),
103 'nl-iso-8859-1'=> array('nl([-_][[:alpha:]]{2})?|dutch', 'dutch-iso-8859-1', 'nl'),
104 'no-utf-8' => array('no|norwegian', 'norwegian-utf-8', 'no'),
105 'no-iso-8859-1'=> array('no|norwegian', 'norwegian-iso-8859-1', 'no'),
106 'pl-utf-8' => array('pl|polish', 'polish-utf-8', 'pl'),
107 'pl-iso-8859-2'=> array('pl|polish', 'polish-iso-8859-2', 'pl'),
108 'pt-br-utf-8' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-utf-8', 'pt-BR'),
109 'pt-br-iso-8859-1' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-iso-8859-1', 'pt-BR'),
110 'pt-utf-8' => array('pt([-_][[:alpha:]]{2})?|portuguese', 'portuguese-utf-8', 'pt'),
111 'pt-iso-8859-1'=> array('pt([-_][[:alpha:]]{2})?|portuguese', 'portuguese-iso-8859-1', 'pt'),
112 'ro-utf-8' => array('ro|romanian', 'romanian-utf-8', 'ro'),
113 'ro-iso-8859-1'=> array('ro|romanian', 'romanian-iso-8859-1', 'ro'),
114 'ru-utf-8' => array('ru|russian', 'russian-utf-8', 'ru'),
115 'ru-koi8-r' => array('ru|russian', 'russian-koi8-r', 'ru'),
116 'ru-win1251' => array('ru|russian', 'russian-windows-1251', 'ru'),
117 'sk-utf-8' => array('sk|slovak', 'slovak-utf-8', 'sk'),
118 'sk-iso-8859-2'=> array('sk|slovak', 'slovak-iso-8859-2', 'sk'),
119 'sk-win1250' => array('sk|slovak', 'slovak-windows-1250', 'sk'),
120 'sl-utf-8' => array('sl|slovenian', 'slovenian-utf-8', 'sl'),
121 'sl-iso-8859-2'=> array('sl|slovenian', 'slovenian-iso-8859-2', 'sl'),
122 'sl-win1250' => array('sl|slovenian', 'slovenian-windows-1250', 'sl'),
123 'sq-utf-8' => array('sq|albanian', 'albanian-utf-8', 'sq'),
124 'sq-iso-8859-1'=> array('sq|albanian', 'albanian-iso-8859-1', 'sq'),
125 'sr-utf-8' => array('sr|serbian', 'serbian-utf-8', 'sr'),
126 'sr-win1250' => array('sr|serbian', 'serbian-windows-1250', 'sr'),
127 'sv-utf-8' => array('sv|swedish', 'swedish-utf-8', 'sv'),
128 'sv-iso-8859-1'=> array('sv|swedish', 'swedish-iso-8859-1', 'sv'),
129 'th-utf-8' => array('th|thai', 'thai-utf-8', 'th'),
130 'th-tis-620' => array('th|thai', 'thai-tis-620', 'th'),
131 'tr-utf-8' => array('tr|turkish', 'turkish-utf-8', 'tr'),
132 'tr-iso-8859-9'=> array('tr|turkish', 'turkish-iso-8859-9', 'tr'),
133 'uk-utf-8' => array('uk|ukrainian', 'ukrainian-utf-8', 'uk'),
134 'uk-win1251' => array('uk|ukrainian', 'ukrainian-windows-1251', 'uk'),
135 'zh-tw-utf-8' => array('zh[-_]tw|chinese traditional', 'chinese_big5-utf-8', 'zh-TW'),
136 'zh-tw' => array('zh[-_]tw|chinese traditional', 'chinese_big5', 'zh-TW'),
137 'zh-utf-8' => array('zh|chinese simplified', 'chinese_gb-utf-8', 'zh'),
138 'zh' => array('zh|chinese simplified', 'chinese_gb', 'zh')
142 if (!defined('PMA_IS_LANG_DETECT_FUNCTION')) {
143 define('PMA_IS_LANG_DETECT_FUNCTION', 1);
146 * Analyzes some PHP environment variables to find the most probable language
147 * that should be used
149 * @param string string to analyze
150 * @param integer type of the PHP environment variable which value is $str
152 * @global array the list of available translations
153 * @global string the retained translation keyword
155 * @access private
157 function PMA_langDetect($str = '', $envType = '')
159 global $available_languages;
160 global $lang;
162 reset($available_languages);
163 while (list($key, $value) = each($available_languages)) {
164 // $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable,
165 // 2 for the 'HTTP_USER_AGENT' one
166 if (($envType == 1 && eregi('^(' . $value[0] . ')(;q=[0-9]\\.[0-9])?$', $str))
167 || ($envType == 2 && eregi('(\(|\[|;[[:space:]])(' . $value[0] . ')(;|\]|\))', $str))) {
168 $lang = $key;
169 break;
172 } // end of the 'PMA_langDetect()' function
174 } // end if
178 * Get some global variables if 'register_globals' is set to 'off'
179 * loic1 - 2001/25/11: use the new globals arrays defined with php 4.1+
181 if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
182 $HTTP_ACCEPT_LANGUAGE = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
184 else if (!empty($HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE'])) {
185 $HTTP_ACCEPT_LANGUAGE = $HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE'];
188 if (!empty($_SERVER['HTTP_USER_AGENT'])) {
189 $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
191 else if (!empty($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) {
192 $HTTP_USER_AGENT = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
195 if (!isset($lang)) {
196 if (isset($_GET) && !empty($_GET['lang'])) {
197 $lang = $_GET['lang'];
199 else if (isset($HTTP_GET_VARS) && !empty($HTTP_GET_VARS['lang'])) {
200 $lang = $HTTP_GET_VARS['lang'];
202 else if (isset($_POST) && !empty($_POST['lang'])) {
203 $lang = $_POST['lang'];
205 else if (isset($HTTP_POST_VARS) && !empty($HTTP_POST_VARS['lang'])) {
206 $lang = $HTTP_POST_VARS['lang'];
208 else if (isset($_COOKIE) && !empty($_COOKIE['lang'])) {
209 $lang = $_COOKIE['lang'];
211 else if (isset($HTTP_COOKIE_VARS) && !empty($HTTP_COOKIE_VARS['lang'])) {
212 $lang = $HTTP_COOKIE_VARS['lang'];
218 * Do the work!
221 // compatibility with config.inc.php3 <= v1.80
222 if (!isset($cfg['Lang']) && isset($cfgLang)) {
223 $cfg['Lang'] = $cfgLang;
224 unset($cfgLang);
226 if (!isset($cfg['DefaultLang']) && isset($cfgDefaultLang)) {
227 $cfg['DefaultLang'] = $cfgDefaultLang;
228 unset($cfgLang);
231 // Disable UTF-8 if $cfg['AllowAnywhereRecoding'] has been set to FALSE.
232 if (!isset($cfg['AllowAnywhereRecoding']) || !$cfg['AllowAnywhereRecoding']) {
233 $available_language_files = $available_languages;
234 $available_languages = array();
235 while (list($tmp_lang, $tmp_lang_data) = each($available_language_files)) {
236 if (substr($tmp_lang, -5) != 'utf-8') {
237 $available_languages[$tmp_lang] = $tmp_lang_data;
239 } // end while
240 unset($tmp_lang);
241 unset($tmp_lang_data);
242 unset($available_language_files);
243 } // end if
245 // Lang forced
246 if (!empty($cfg['Lang'])) {
247 $lang = $cfg['Lang'];
250 // If '$lang' is defined, ensure this is a valid translation
251 if (!empty($lang) && empty($available_languages[$lang])) {
252 $lang = '';
255 // Language is not defined yet :
256 // 1. try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE
257 // variable
258 if (empty($lang) && !empty($HTTP_ACCEPT_LANGUAGE)) {
259 $accepted = explode(',', $HTTP_ACCEPT_LANGUAGE);
260 $acceptedCnt = count($accepted);
261 reset($accepted);
262 for ($i = 0; $i < $acceptedCnt && empty($lang); $i++) {
263 PMA_langDetect($accepted[$i], 1);
266 // 2. try to findout user's language by checking its HTTP_USER_AGENT variable
267 if (empty($lang) && !empty($HTTP_USER_AGENT)) {
268 PMA_langDetect($HTTP_USER_AGENT, 2);
271 // 3. Didn't catch any valid lang : we use the default settings
272 if (empty($lang)) {
273 $lang = $cfg['DefaultLang'];
276 // 4. Checks whether charset recoding should be allowed or not
277 $allow_recoding = FALSE; // Default fallback value
278 if (!isset($convcharset) || empty($convcharset)) {
279 $convcharset = $cfg['DefaultCharset'];
282 // 5. Defines the associated filename and load the translation
283 $lang_file = $lang_path . $available_languages[$lang][1] . '.inc.php3';
284 include('./' . $lang_file);
286 } // $__PMA_SELECT_LANG_LIB__