[ Index ] |
|
Code source de phpMyAdmin 2.10.3 |
1 <?php 2 /* $Id: select_lang.lib.php 10430 2007-06-10 19:28:56Z lem9 $ */ 3 // vim: expandtab sw=4 ts=4 sts=4: 4 5 /** 6 * phpMyAdmin Language Loading File 7 */ 8 9 /** 10 * trys to find the language to use 11 * 12 * @uses $GLOBALS['cfg']['lang'] 13 * @uses $GLOBALS['cfg']['DefaultLang'] 14 * @uses $GLOBALS['lang_failed_cfg'] 15 * @uses $GLOBALS['lang_failed_cookie'] 16 * @uses $GLOBALS['lang_failed_request'] 17 * @uses $_REQUEST['lang'] 18 * @uses $_COOKIE['pma_lang'] 19 * @uses $_SERVER['HTTP_ACCEPT_LANGUAGE'] 20 * @uses $_SERVER['HTTP_USER_AGENT'] 21 * @uses PMA_langSet() 22 * @uses PMA_langDetect() 23 * @uses explode() 24 * @return bool success if valid lang is found, otherwise false 25 */ 26 function PMA_langCheck() 27 { 28 // check forced language 29 if (! empty($GLOBALS['cfg']['Lang'])) { 30 if (PMA_langSet($GLOBALS['cfg']['Lang'])) { 31 return true; 32 } else { 33 $GLOBALS['lang_failed_cfg'] = $GLOBALS['cfg']['Lang']; 34 } 35 } 36 37 // Don't use REQUEST in following code as it might be confused by cookies with same name 38 // check user requested language (POST) 39 if (! empty($_POST['lang'])) { 40 if (PMA_langSet($_POST['lang'])) { 41 return true; 42 } elseif (!is_string($_POST['lang'])) { 43 /* Faked request, don't care on localisation */ 44 $GLOBALS['lang_failed_request'] = 'Yes'; 45 } else { 46 $GLOBALS['lang_failed_request'] = $_POST['lang']; 47 } 48 } 49 50 // check user requested language (GET) 51 if (! empty($_GET['lang'])) { 52 if (PMA_langSet($_GET['lang'])) { 53 return true; 54 } elseif (!is_string($_GET['lang'])) { 55 /* Faked request, don't care on localisation */ 56 $GLOBALS['lang_failed_request'] = 'Yes'; 57 } else { 58 $GLOBALS['lang_failed_request'] = $_GET['lang']; 59 } 60 } 61 62 // check previous set language 63 if (! empty($_COOKIE['pma_lang'])) { 64 if (PMA_langSet($_COOKIE['pma_lang'])) { 65 return true; 66 } elseif (!is_string($_COOKIE['lang'])) { 67 /* Faked request, don't care on localisation */ 68 $GLOBALS['lang_failed_request'] = 'Yes'; 69 } else { 70 $GLOBALS['lang_failed_cookie'] = $_COOKIE['pma_lang']; 71 } 72 } 73 74 // try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE variable 75 if (PMA_getenv('HTTP_ACCEPT_LANGUAGE')) { 76 foreach (explode(',', PMA_getenv('HTTP_ACCEPT_LANGUAGE')) as $lang) { 77 if (PMA_langDetect($lang, 1)) { 78 return true; 79 } 80 } 81 } 82 83 // try to findout user's language by checking its HTTP_USER_AGENT variable 84 if (PMA_langDetect(PMA_getenv('HTTP_USER_AGENT'), 2)) { 85 return true; 86 } 87 88 // Didn't catch any valid lang : we use the default settings 89 if (PMA_langSet($GLOBALS['cfg']['DefaultLang'])) { 90 return true; 91 } 92 93 return false; 94 } 95 96 /** 97 * checks given lang and sets it if valid 98 * returns true on success, otherwise flase 99 * 100 * @uses $GLOBALS['available_languages'] to check $lang 101 * @uses $GLOBALS['lang'] to set it 102 * @param string $lang language to set 103 * @return bool success 104 */ 105 function PMA_langSet(&$lang) 106 { 107 if (!is_string($lang) || empty($lang) || empty($GLOBALS['available_languages'][$lang])) { 108 return false; 109 } 110 $GLOBALS['lang'] = $lang; 111 return true; 112 } 113 114 /** 115 * Analyzes some PHP environment variables to find the most probable language 116 * that should be used 117 * 118 * @param string string to analyze 119 * @param integer type of the PHP environment variable which value is $str 120 * 121 * @return bool true on success, otherwise false 122 * 123 * @global $available_languages 124 * 125 * @access private 126 */ 127 function PMA_langDetect(&$str, $envType) 128 { 129 if (empty($str)) { 130 return false; 131 } 132 if (empty($GLOBALS['available_languages'])) { 133 return false; 134 } 135 136 foreach ($GLOBALS['available_languages'] as $lang => $value) { 137 // $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable, 138 // 2 for the 'HTTP_USER_AGENT' one 139 $expr = $value[0]; 140 if (strpos($expr, '[-_]') === FALSE) { 141 $expr = str_replace('|', '([-_][[:alpha:]]{2,3})?|', $expr); 142 } 143 if (($envType == 1 && eregi('^(' . $expr . ')(;q=[0-9]\\.[0-9])?$', $str)) 144 || ($envType == 2 && eregi('(\(|\[|;[[:space:]])(' . $expr . ')(;|\]|\))', $str))) { 145 if (PMA_langSet($lang)) { 146 return true; 147 } 148 } 149 } 150 151 return false; 152 } // end of the 'PMA_langDetect()' function 153 154 /** 155 * @var string path to the translations directory 156 */ 157 $lang_path = './lang/'; 158 159 /** 160 * first check for lang dir exists 161 */ 162 if (! is_dir($lang_path)) { 163 // language directory not found 164 trigger_error('phpMyAdmin-ERROR: path not found: ' 165 . $lang_path . ', check your language directory.', 166 E_USER_WARNING); 167 // and tell the user 168 PMA_sendHeaderLocation('error.php?error=' 169 . urlencode( 'path to languages is invalid: ' . $lang_path)); 170 // stop execution 171 exit; 172 } 173 174 /** 175 * @var string interface language 176 */ 177 $GLOBALS['lang'] = ''; 178 /** 179 * @var boolean wether loading lang from cfg failed 180 */ 181 $lang_failed_cfg = false; 182 /** 183 * @var boolean wether loading lang from cookie failed 184 */ 185 $lang_failed_cookie = false; 186 /** 187 * @var boolean wether loading lang from user request failed 188 */ 189 $lang_failed_request = false; 190 191 192 /** 193 * All the supported languages have to be listed in the array below. 194 * 1. The key must be the "official" ISO 639 language code and, if required, 195 * the dialect code. It can also contain some informations about the 196 * charset (see the Russian case). 197 * 2. The first of the values associated to the key is used in a regular 198 * expression to find some keywords corresponding to the language inside two 199 * environment variables. 200 * These values contains: 201 * - the "official" ISO language code and, if required, the dialect code 202 * also ('bu' for Bulgarian, 'fr([-_][[:alpha:]]{2})?' for all French 203 * dialects, 'zh[-_]tw' for Chinese traditional...), the dialect has to 204 * be specified as first; 205 * - the '|' character (it means 'OR'); 206 * - the full language name. 207 * 3. The second values associated to the key is the name of the file to load 208 * without the 'inc.php' extension. 209 * 4. The third values associated to the key is the language code as defined by 210 * the RFC1766. 211 * 5. The fourth value is native name in html entities. 212 * 213 * Beware that the sorting order (first values associated to keys by 214 * alphabetical reverse order in the array) is important: 'zh-tw' (chinese 215 * traditional) must be detected before 'zh' (chinese simplified) for 216 * example. 217 * 218 * When there are more than one charset for a language, we put the -utf-8 219 * last because we need the default charset to be non-utf-8 to avoid 220 * problems on MySQL < 4.1.x if AllowAnywhereRecoding is FALSE. 221 * 222 * For Russian, we put 1251 first, because MSIE does not accept 866 223 * and users would not see anything. 224 */ 225 $available_languages = array( 226 'af-utf-8' => array('af|afrikaans', 'afrikaans-utf-8', 'af', ''), 227 'ar-utf-8' => array('ar|arabic', 'arabic-utf-8', 'ar', 'العربية'), 228 'az-utf-8' => array('az|azerbaijani', 'azerbaijani-utf-8', 'az', 'Azərbaycanca'), 229 'becyr-utf-8' => array('be|belarusian', 'belarusian_cyrillic-utf-8', 'be', 'Беларуская'), 230 'belat-utf-8' => array('be[-_]lat|belarusian latin', 'belarusian_latin-utf-8', 'be-lat', 'Byelorussian'), 231 'bg-utf-8' => array('bg|bulgarian', 'bulgarian-utf-8', 'bg', 'Български'), 232 'bs-utf-8' => array('bs|bosnian', 'bosnian-utf-8', 'bs', 'Bosanski'), 233 'ca-utf-8' => array('ca|catalan', 'catalan-utf-8', 'ca', 'Català'), 234 'cs-utf-8' => array('cs|czech', 'czech-utf-8', 'cs', 'Česky'), 235 'da-utf-8' => array('da|danish', 'danish-utf-8', 'da', 'Dansk'), 236 'de-utf-8' => array('de|german', 'german-utf-8', 'de', 'Deutsch'), 237 'el-utf-8' => array('el|greek', 'greek-utf-8', 'el', 'Ελληνικά'), 238 'en-utf-8' => array('en|english', 'english-utf-8', 'en', ''), 239 'es-utf-8' => array('es|spanish', 'spanish-utf-8', 'es', 'Español'), 240 'et-utf-8' => array('et|estonian', 'estonian-utf-8', 'et', 'Eesti'), 241 'eu-utf-8' => array('eu|basque', 'basque-utf-8', 'eu', 'Euskara'), 242 'fa-utf-8' => array('fa|persian', 'persian-utf-8', 'fa', 'فارسی'), 243 'fi-utf-8' => array('fi|finnish', 'finnish-utf-8', 'fi', 'Suomi'), 244 'fr-utf-8' => array('fr|french', 'french-utf-8', 'fr', 'Français'), 245 'gl-utf-8' => array('gl|galician', 'galician-utf-8', 'gl', 'Galego'), 246 'he-utf-8' => array('he|hebrew', 'hebrew-utf-8', 'he', 'עברית'), 247 'hi-utf-8' => array('hi|hindi', 'hindi-utf-8', 'hi', 'हिन्दी'), 248 'hr-utf-8' => array('hr|croatian', 'croatian-utf-8', 'hr', 'Hrvatski'), 249 'hu-utf-8' => array('hu|hungarian', 'hungarian-utf-8', 'hu', 'Magyar'), 250 'id-utf-8' => array('id|indonesian', 'indonesian-utf-8', 'id', 'Bahasa Indonesia'), 251 'it-utf-8' => array('it|italian', 'italian-utf-8', 'it', 'Italiano'), 252 'ja-utf-8' => array('ja|japanese', 'japanese-utf-8', 'ja', '日本語'), 253 'ko-utf-8' => array('ko|korean', 'korean-utf-8', 'ko', '한국어'), 254 'ka-utf-8' => array('ka|georgian', 'georgian-utf-8', 'ka', 'ქართული'), 255 'lt-utf-8' => array('lt|lithuanian', 'lithuanian-utf-8', 'lt', 'Lietuvių'), 256 'lv-utf-8' => array('lv|latvian', 'latvian-utf-8', 'lv', 'Latviešu'), 257 'mn-utf-8' => array('mn|mongolian', 'mongolian-utf-8', 'mn', 'Монгол'), 258 'ms-utf-8' => array('ms|malay', 'malay-utf-8', 'ms', 'Bahasa Melayu'), 259 'nl-utf-8' => array('nl|dutch', 'dutch-utf-8', 'nl', 'Nederlands'), 260 'no-utf-8' => array('no|norwegian', 'norwegian-utf-8', 'no', 'Norsk'), 261 'pl-utf-8' => array('pl|polish', 'polish-utf-8', 'pl', 'Polski'), 262 'ptbr-utf-8' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-utf-8', 'pt-BR', 'Português'), 263 'pt-utf-8' => array('pt|portuguese', 'portuguese-utf-8', 'pt', 'Português'), 264 'ro-utf-8' => array('ro|romanian', 'romanian-utf-8', 'ro', 'Română'), 265 'ru-utf-8' => array('ru|russian', 'russian-utf-8', 'ru', 'Русский'), 266 'sk-utf-8' => array('sk|slovak', 'slovak-utf-8', 'sk', 'Slovenčina'), 267 'sl-utf-8' => array('sl|slovenian', 'slovenian-utf-8', 'sl', 'Slovenščina'), 268 'sq-utf-8' => array('sq|albanian', 'albanian-utf-8', 'sq', 'Shqip'), 269 'srlat-utf-8' => array('sr[-_]lat|serbian latin', 'serbian_latin-utf-8', 'sr-lat', 'Srpski'), 270 'srcyr-utf-8' => array('sr|serbian', 'serbian_cyrillic-utf-8', 'sr', 'Српски'), 271 'sv-utf-8' => array('sv|swedish', 'swedish-utf-8', 'sv', 'Svenska'), 272 'th-utf-8' => array('th|thai', 'thai-utf-8', 'th', 'ภาษาไทย'), 273 'tr-utf-8' => array('tr|turkish', 'turkish-utf-8', 'tr', 'Türkçe'), 274 'tt-utf-8' => array('tt|tatarish', 'tatarish-utf-8', 'tt', 'Tatarça'), 275 'uk-utf-8' => array('uk|ukrainian', 'ukrainian-utf-8', 'uk', 'Українська'), 276 'zhtw-utf-8' => array('zh[-_](tw|hk)|chinese traditional', 'chinese_traditional-utf-8', 'zh-TW', '中文'), 277 'zh-utf-8' => array('zh|chinese simplified', 'chinese_simplified-utf-8', 'zh', '中文'), 278 ); 279 280 // Language filtering support 281 if (! empty($GLOBALS['cfg']['FilterLanguages'])) { 282 $new_lang = array(); 283 foreach ($available_languages as $key => $val) { 284 if (preg_match('@' . $GLOBALS['cfg']['FilterLanguages'] . '@', $key)) { 285 $new_lang[$key] = $val; 286 } 287 } 288 if (count($new_lang) > 0) { 289 $available_languages = $new_lang; 290 } 291 unset($key, $val, $new_lang); 292 } 293 294 /** 295 * check for language files 296 */ 297 foreach ($available_languages as $each_lang_key => $each_lang) { 298 if (! file_exists($lang_path . $each_lang[1] . '.inc.php')) { 299 unset($available_languages[$each_lang_key]); 300 } 301 } 302 unset($each_lang_key, $each_lang); 303 304 // MySQL charsets map 305 $mysql_charset_map = array( 306 'big5' => 'big5', 307 'cp-866' => 'cp866', 308 'euc-jp' => 'ujis', 309 'euc-kr' => 'euckr', 310 'gb2312' => 'gb2312', 311 'gbk' => 'gbk', 312 'iso-8859-1' => 'latin1', 313 'iso-8859-2' => 'latin2', 314 'iso-8859-7' => 'greek', 315 'iso-8859-8' => 'hebrew', 316 'iso-8859-8-i' => 'hebrew', 317 'iso-8859-9' => 'latin5', 318 'iso-8859-13' => 'latin7', 319 'iso-8859-15' => 'latin1', 320 'koi8-r' => 'koi8r', 321 'shift_jis' => 'sjis', 322 'tis-620' => 'tis620', 323 'utf-8' => 'utf8', 324 'windows-1250' => 'cp1250', 325 'windows-1251' => 'cp1251', 326 'windows-1252' => 'latin1', 327 'windows-1256' => 'cp1256', 328 'windows-1257' => 'cp1257', 329 ); 330 331 /** 332 * Do the work! 333 */ 334 // Checks whether charset recoding should be allowed or not 335 $allow_recoding = FALSE; // Default fallback value 336 if (empty($convcharset)) { 337 if (isset($_COOKIE['pma_charset'])) { 338 $convcharset = $_COOKIE['pma_charset']; 339 } else { 340 // session.save_path might point to a bad folder 341 $convcharset = isset($GLOBALS['cfg']['DefaultCharset']) ? $GLOBALS['cfg']['DefaultCharset'] : 'en-utf-8'; 342 } 343 } 344 345 if (! PMA_langCheck()) { 346 // fallback language 347 $fall_back_lang = 'en-utf-8'; $line = __LINE__; 348 if (! PMA_langSet($fall_back_lang)) { 349 trigger_error('phpMyAdmin-ERROR: invalid lang code: ' 350 . __FILE__ . '#' . $line . ', check hard coded fall back language.', 351 E_USER_WARNING); 352 // stop execution 353 // and tell the user that his choosen language is invalid 354 PMA_sendHeaderLocation('error.php?error=' 355 . urlencode('Could not load any language, please check your language settings and folder')); 356 exit; 357 } 358 } 359 360 // Defines the associated filename and load the translation 361 $lang_file = $lang_path . $available_languages[$GLOBALS['lang']][1] . '.inc.php'; 362 require_once $lang_file; 363 364 // now, that we have loaded the language strings we can send the errors 365 if ($lang_failed_cfg) { 366 $GLOBALS['PMA_errors'][] = sprintf($strLanguageUnknown, htmlspecialchars($lang_failed_cfg)); 367 } 368 if ($lang_failed_cookie) { 369 $GLOBALS['PMA_errors'][] = sprintf($strLanguageUnknown, htmlspecialchars($lang_failed_cookie)); 370 } 371 if ($lang_failed_request) { 372 $GLOBALS['PMA_errors'][] = sprintf($strLanguageUnknown, htmlspecialchars($lang_failed_request)); 373 } 374 375 unset($line, $fall_back_lang, 376 $lang_failed_cfg, $lang_failed_cookie, $lang_failed_request, $strLanguageUnknown); 377 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 15:18:20 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |