Documentation TYPO3 par Ameos |
00001 <?php 00002 /* $Id: select_lang.lib.php,v 2.4 2003/12/08 19:17:31 lem9 Exp $ */ 00003 // vim: expandtab sw=4 ts=4 sts=4: 00004 00005 00014 require_once('./libraries/grab_globals.lib.php'); 00015 00016 00021 $lang_path = 'lang/'; 00022 00023 00054 $available_languages = array( 00055 'af-utf-8' => array('af|afrikaans', 'afrikaans-utf-8', 'af'), 00056 'af-iso-8859-1'=> array('af|afrikaans', 'afrikaans-iso-8859-1', 'af'), 00057 'ar-utf-8' => array('ar([-_][[:alpha:]]{2})?|arabic', 'arabic-utf-8', 'ar'), 00058 'ar-win1256' => array('ar([-_][[:alpha:]]{2})?|arabic', 'arabic-windows-1256', 'ar'), 00059 'az-utf-8' => array('az|azerbaijani', 'azerbaijani-utf-8', 'az'), 00060 'az-iso-8859-9'=> array('az|azerbaijani', 'azerbaijani-iso-8859-9', 'az'), 00061 'bg-utf-8' => array('bg|bulgarian', 'bulgarian-utf-8', 'bg'), 00062 'bg-win1251' => array('bg|bulgarian', 'bulgarian-windows-1251', 'bg'), 00063 'bg-koi8-r' => array('bg|bulgarian', 'bulgarian-koi8-r', 'bg'), 00064 'bs-utf-8' => array('bs|bosnian', 'bosnian-utf-8', 'bs'), 00065 'bs-win1250' => array('bs|bosnian', 'bosnian-windows-1250', 'bs'), 00066 'ca-utf-8' => array('ca|catalan', 'catalan-utf-8', 'ca'), 00067 'ca-iso-8859-1'=> array('ca|catalan', 'catalan-iso-8859-1', 'ca'), 00068 'cs-utf-8' => array('cs|czech', 'czech-utf-8', 'cs'), 00069 'cs-iso-8859-2'=> array('cs|czech', 'czech-iso-8859-2', 'cs'), 00070 'cs-win1250' => array('cs|czech', 'czech-windows-1250', 'cs'), 00071 'da-utf-8' => array('da|danish', 'danish-utf-8', 'da'), 00072 'da-iso-8859-1'=> array('da|danish', 'danish-iso-8859-1', 'da'), 00073 'de-utf-8' => array('de([-_][[:alpha:]]{2})?|german', 'german-utf-8', 'de'), 00074 'de-iso-8859-1'=> array('de([-_][[:alpha:]]{2})?|german', 'german-iso-8859-1', 'de'), 00075 'el-utf-8' => array('el|greek', 'greek-utf-8', 'el'), 00076 'el-iso-8859-7'=> array('el|greek', 'greek-iso-8859-7', 'el'), 00077 'en-utf-8' => array('en([-_][[:alpha:]]{2})?|english', 'english-utf-8', 'en'), 00078 'en-iso-8859-1'=> array('en([-_][[:alpha:]]{2})?|english', 'english-iso-8859-1', 'en'), 00079 'es-utf-8' => array('es([-_][[:alpha:]]{2})?|spanish', 'spanish-utf-8', 'es'), 00080 'es-iso-8859-1'=> array('es([-_][[:alpha:]]{2})?|spanish', 'spanish-iso-8859-1', 'es'), 00081 'et-utf-8' => array('et|estonian', 'estonian-utf-8', 'et'), 00082 'et-iso-8859-1'=> array('et|estonian', 'estonian-iso-8859-1', 'et'), 00083 'eu-utf-8' => array('eu|basque', 'basque-utf-8', 'eu'), 00084 'eu-iso-8859-1'=> array('eu|basque', 'basque-iso-8859-1', 'eu'), 00085 'fa-utf-8' => array('fa|persian', 'persian-utf-8', 'fa'), 00086 'fa-win1256' => array('fa|persian', 'persian-windows-1256', 'fa'), 00087 'fi-utf-8' => array('fi|finnish', 'finnish-utf-8', 'fi'), 00088 'fi-iso-8859-1'=> array('fi|finnish', 'finnish-iso-8859-1', 'fi'), 00089 'fr-utf-8' => array('fr([-_][[:alpha:]]{2})?|french', 'french-utf-8', 'fr'), 00090 'fr-iso-8859-1'=> array('fr([-_][[:alpha:]]{2})?|french', 'french-iso-8859-1', 'fr'), 00091 'gl-utf-8' => array('gl|galician', 'galician-utf-8', 'gl'), 00092 'gl-iso-8859-1'=> array('gl|galician', 'galician-iso-8859-1', 'gl'), 00093 'he-iso-8859-8-i'=> array('he|hebrew', 'hebrew-iso-8859-8-i', 'he'), 00094 'hi-utf-8' => array('hi|hindi', 'hindi-utf-8', 'hi'), 00095 'hr-utf-8' => array('hr|croatian', 'croatian-utf-8', 'hr'), 00096 'hr-win1250' => array('hr|croatian', 'croatian-windows-1250', 'hr'), 00097 'hr-iso-8859-2'=> array('hr|croatian', 'croatian-iso-8859-2', 'hr'), 00098 'hu-utf-8' => array('hu|hungarian', 'hungarian-utf-8', 'hu'), 00099 'hu-iso-8859-2'=> array('hu|hungarian', 'hungarian-iso-8859-2', 'hu'), 00100 'id-utf-8' => array('id|indonesian', 'indonesian-utf-8', 'id'), 00101 'id-iso-8859-1'=> array('id|indonesian', 'indonesian-iso-8859-1', 'id'), 00102 'it-utf-8' => array('it|italian', 'italian-utf-8', 'it'), 00103 'it-iso-8859-1'=> array('it|italian', 'italian-iso-8859-1', 'it'), 00104 'ja-utf-8' => array('ja|japanese', 'japanese-utf-8', 'ja'), 00105 'ja-euc' => array('ja|japanese', 'japanese-euc', 'ja'), 00106 'ja-sjis' => array('ja|japanese', 'japanese-sjis', 'ja'), 00107 'ko-ks_c_5601-1987'=> array('ko|korean', 'korean-ks_c_5601-1987', 'ko'), 00108 'ka-utf-8' => array('ka|georgian', 'georgian-utf-8', 'ka'), 00109 'lt-utf-8' => array('lt|lithuanian', 'lithuanian-utf-8', 'lt'), 00110 'lt-win1257' => array('lt|lithuanian', 'lithuanian-windows-1257', 'lt'), 00111 'lv-utf-8' => array('lv|latvian', 'latvian-utf-8', 'lv'), 00112 'lv-win1257' => array('lv|latvian', 'latvian-windows-1257', 'lv'), 00113 'ms-utf-8' => array('ms|malay', 'malay-utf-8', 'ms'), 00114 'ms-iso-8859-1'=> array('ms|malay', 'malay-iso-8859-1', 'ms'), 00115 'nl-utf-8' => array('nl([-_][[:alpha:]]{2})?|dutch', 'dutch-utf-8', 'nl'), 00116 'nl-iso-8859-1'=> array('nl([-_][[:alpha:]]{2})?|dutch', 'dutch-iso-8859-1', 'nl'), 00117 'no-utf-8' => array('no|norwegian', 'norwegian-utf-8', 'no'), 00118 'no-iso-8859-1'=> array('no|norwegian', 'norwegian-iso-8859-1', 'no'), 00119 'pl-utf-8' => array('pl|polish', 'polish-utf-8', 'pl'), 00120 'pl-iso-8859-2'=> array('pl|polish', 'polish-iso-8859-2', 'pl'), 00121 'pt-br-utf-8' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-utf-8', 'pt-BR'), 00122 'pt-br-iso-8859-1' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-iso-8859-1', 'pt-BR'), 00123 'pt-utf-8' => array('pt([-_][[:alpha:]]{2})?|portuguese', 'portuguese-utf-8', 'pt'), 00124 'pt-iso-8859-1'=> array('pt([-_][[:alpha:]]{2})?|portuguese', 'portuguese-iso-8859-1', 'pt'), 00125 'ro-utf-8' => array('ro|romanian', 'romanian-utf-8', 'ro'), 00126 'ro-iso-8859-1'=> array('ro|romanian', 'romanian-iso-8859-1', 'ro'), 00127 'ru-win1251' => array('ru|russian', 'russian-windows-1251', 'ru'), 00128 'ru-utf-8' => array('ru|russian', 'russian-utf-8', 'ru'), 00129 'ru-dos-866' => array('ru|russian', 'russian-dos-866', 'ru'), 00130 'ru-koi8-r' => array('ru|russian', 'russian-koi8-r', 'ru'), 00131 'sk-utf-8' => array('sk|slovak', 'slovak-utf-8', 'sk'), 00132 'sk-iso-8859-2'=> array('sk|slovak', 'slovak-iso-8859-2', 'sk'), 00133 'sk-win1250' => array('sk|slovak', 'slovak-windows-1250', 'sk'), 00134 'sl-utf-8' => array('sl|slovenian', 'slovenian-utf-8', 'sl'), 00135 'sl-iso-8859-2'=> array('sl|slovenian', 'slovenian-iso-8859-2', 'sl'), 00136 'sl-win1250' => array('sl|slovenian', 'slovenian-windows-1250', 'sl'), 00137 'sq-utf-8' => array('sq|albanian', 'albanian-utf-8', 'sq'), 00138 'sq-iso-8859-1'=> array('sq|albanian', 'albanian-iso-8859-1', 'sq'), 00139 'sr-utf-8' => array('sr|serbian', 'serbian_cyrillic-utf-8', 'sr'), 00140 'sr-win1251' => array('sr|serbian', 'serbian_cyrillic-windows-1251', 'sr'), 00141 'sr-lat-utf-8' => array('sr[-_]lat|serbian latin', 'serbian_latin-utf-8', 'sr-lat'), 00142 'sr-lat-win1250'=> array('sr[-_]lat|serbian latin', 'serbian_latin-windows-1250', 'sr-lat'), 00143 'sv-utf-8' => array('sv|swedish', 'swedish-utf-8', 'sv'), 00144 'sv-iso-8859-1'=> array('sv|swedish', 'swedish-iso-8859-1', 'sv'), 00145 'th-utf-8' => array('th|thai', 'thai-utf-8', 'th'), 00146 'th-tis-620' => array('th|thai', 'thai-tis-620', 'th'), 00147 'tr-utf-8' => array('tr|turkish', 'turkish-utf-8', 'tr'), 00148 'tr-iso-8859-9'=> array('tr|turkish', 'turkish-iso-8859-9', 'tr'), 00149 'uk-utf-8' => array('uk|ukrainian', 'ukrainian-utf-8', 'uk'), 00150 'uk-win1251' => array('uk|ukrainian', 'ukrainian-windows-1251', 'uk'), 00151 'zh-tw-utf-8' => array('zh[-_]tw|chinese traditional', 'chinese_big5-utf-8', 'zh-TW'), 00152 'zh-tw' => array('zh[-_]tw|chinese traditional', 'chinese_big5', 'zh-TW'), 00153 'zh-utf-8' => array('zh|chinese simplified', 'chinese_gb-utf-8', 'zh'), 00154 'zh' => array('zh|chinese simplified', 'chinese_gb', 'zh') 00155 ); 00156 00157 00170 function PMA_langDetect($str = '', $envType = '') 00171 { 00172 global $available_languages; 00173 global $lang; 00174 00175 foreach($available_languages AS $key => $value) { 00176 // $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable, 00177 // 2 for the 'HTTP_USER_AGENT' one 00178 if (($envType == 1 && eregi('^(' . $value[0] . ')(;q=[0-9]\\.[0-9])?$', $str)) 00179 || ($envType == 2 && eregi('(\(|\[|;[[:space:]])(' . $value[0] . ')(;|\]|\))', $str))) { 00180 $lang = $key; 00181 break; 00182 } 00183 } 00184 } // end of the 'PMA_langDetect()' function 00185 00186 00187 if (!isset($lang)) { 00188 if (isset($_GET) && !empty($_GET['lang'])) { 00189 $lang = $_GET['lang']; 00190 } 00191 else if (isset($_POST) && !empty($_POST['lang'])) { 00192 $lang = $_POST['lang']; 00193 } 00194 else if (isset($_COOKIE) && !empty($_COOKIE['lang'])) { 00195 $lang = $_COOKIE['lang']; 00196 } 00197 } 00198 00199 00204 // compatibility with config.inc.php <= v1.80 00205 if (!isset($cfg['Lang']) && isset($cfgLang)) { 00206 $cfg['Lang'] = $cfgLang; 00207 unset($cfgLang); 00208 } 00209 if (!isset($cfg['DefaultLang']) && isset($cfgDefaultLang)) { 00210 $cfg['DefaultLang'] = $cfgDefaultLang; 00211 unset($cfgLang); 00212 } 00213 00214 // Disable UTF-8 if $cfg['AllowAnywhereRecoding'] has been set to FALSE. 00215 if (!isset($cfg['AllowAnywhereRecoding']) || !$cfg['AllowAnywhereRecoding']) { 00216 $available_language_files = $available_languages; 00217 $available_languages = array(); 00218 foreach($available_language_files AS $tmp_lang => $tmp_lang_data) { 00219 if (substr($tmp_lang, -5) != 'utf-8') { 00220 $available_languages[$tmp_lang] = $tmp_lang_data; 00221 } 00222 } // end while 00223 unset($tmp_lang, $tmp_lang_data, $available_language_files); 00224 } // end if 00225 00226 // Lang forced 00227 if (!empty($cfg['Lang'])) { 00228 $lang = $cfg['Lang']; 00229 } 00230 00231 // If '$lang' is defined, ensure this is a valid translation 00232 if (!empty($lang) && empty($available_languages[$lang])) { 00233 $lang = ''; 00234 } 00235 00236 // Language is not defined yet : 00237 // 1. try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE 00238 // variable 00239 if (empty($lang) && !empty($HTTP_ACCEPT_LANGUAGE)) { 00240 $accepted = explode(',', $HTTP_ACCEPT_LANGUAGE); 00241 $acceptedCnt = count($accepted); 00242 for ($i = 0; $i < $acceptedCnt && empty($lang); $i++) { 00243 PMA_langDetect($accepted[$i], 1); 00244 } 00245 } 00246 // 2. try to findout user's language by checking its HTTP_USER_AGENT variable 00247 if (empty($lang) && !empty($HTTP_USER_AGENT)) { 00248 PMA_langDetect($HTTP_USER_AGENT, 2); 00249 } 00250 00251 // 3. Didn't catch any valid lang : we use the default settings 00252 if (empty($lang)) { 00253 $lang = $cfg['DefaultLang']; 00254 } 00255 00256 // 4. Checks whether charset recoding should be allowed or not 00257 $allow_recoding = FALSE; // Default fallback value 00258 if (!isset($convcharset) || empty($convcharset)) { 00259 $convcharset = $cfg['DefaultCharset']; 00260 } 00261 00262 // 5. Defines the associated filename and load the translation 00263 $lang_file = $lang_path . $available_languages[$lang][1] . '.inc.php'; 00264 require_once('./' . $lang_file); 00265 00266 ?>