Documentation TYPO3 par Ameos

select_lang.lib.php

00001 <?php
00002 /* $Id: select_lang.lib.php,v 2.23 2005/06/11 10:23:21 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 
00056 $available_languages = array(
00057     'af-iso-8859-1'     => array('af|afrikaans', 'afrikaans-iso-8859-1', 'af'),
00058     'af-utf-8'          => array('af|afrikaans', 'afrikaans-utf-8', 'af'),
00059     'ar-win1256'        => array('ar|arabic', 'arabic-windows-1256', 'ar'),
00060     'ar-utf-8'          => array('ar|arabic', 'arabic-utf-8', 'ar'),
00061     'az-iso-8859-9'     => array('az|azerbaijani', 'azerbaijani-iso-8859-9', 'az'),
00062     'az-utf-8'          => array('az|azerbaijani', 'azerbaijani-utf-8', 'az'),
00063 
00064     'becyr-win1251'     => array('be|belarusian', 'belarusian_cyrillic-windows-1251', 'be'),
00065     'becyr-utf-8'       => array('be|belarusian', 'belarusian_cyrillic-utf-8', 'be'),
00066     'belat-utf-8'       => array('be[-_]lat|belarusian latin', 'belarusian_latin-utf-8', 'be-lat'),
00067     'bg-win1251'        => array('bg|bulgarian', 'bulgarian-windows-1251', 'bg'),
00068     'bg-koi8-r'         => array('bg|bulgarian', 'bulgarian-koi8-r', 'bg'),
00069     'bg-utf-8'          => array('bg|bulgarian', 'bulgarian-utf-8', 'bg'),
00070     'bs-win1250'        => array('bs|bosnian', 'bosnian-windows-1250', 'bs'),
00071     'bs-utf-8'          => array('bs|bosnian', 'bosnian-utf-8', 'bs'),
00072     'ca-iso-8859-1'     => array('ca|catalan', 'catalan-iso-8859-1', 'ca'),
00073     'ca-utf-8'          => array('ca|catalan', 'catalan-utf-8', 'ca'),
00074     'cs-iso-8859-2'     => array('cs|czech', 'czech-iso-8859-2', 'cs'),
00075     'cs-win1250'        => array('cs|czech', 'czech-windows-1250', 'cs'),
00076     'cs-utf-8'          => array('cs|czech', 'czech-utf-8', 'cs'),
00077     'da-iso-8859-1'     => array('da|danish', 'danish-iso-8859-1', 'da'),
00078     'da-utf-8'          => array('da|danish', 'danish-utf-8', 'da'),
00079     'de-iso-8859-1'     => array('de|german', 'german-iso-8859-1', 'de'),
00080     'de-iso-8859-15'    => array('de|german', 'german-iso-8859-15', 'de'),
00081     'de-utf-8'          => array('de|german', 'german-utf-8', 'de'),
00082     'el-iso-8859-7'     => array('el|greek',  'greek-iso-8859-7', 'el'),
00083     'el-utf-8'          => array('el|greek',  'greek-utf-8', 'el'),
00084     'en-iso-8859-1'     => array('en|english',  'english-iso-8859-1', 'en'),
00085     'en-iso-8859-15'    => array('en|english',  'english-iso-8859-15', 'en'),
00086     'en-utf-8'          => array('en|english',  'english-utf-8', 'en'),
00087     'es-iso-8859-1'     => array('es|spanish', 'spanish-iso-8859-1', 'es'),
00088     'es-iso-8859-15'    => array('es|spanish', 'spanish-iso-8859-15', 'es'),
00089     'es-utf-8'          => array('es|spanish', 'spanish-utf-8', 'es'),
00090     'et-iso-8859-1'     => array('et|estonian', 'estonian-iso-8859-1', 'et'),
00091     'et-utf-8'          => array('et|estonian', 'estonian-utf-8', 'et'),
00092     'eu-iso-8859-1'     => array('eu|basque', 'basque-iso-8859-1', 'eu'),
00093     'eu-utf-8'          => array('eu|basque', 'basque-utf-8', 'eu'),
00094     'fa-win1256'        => array('fa|persian', 'persian-windows-1256', 'fa'),
00095     'fa-utf-8'          => array('fa|persian', 'persian-utf-8', 'fa'),
00096     'fi-iso-8859-1'     => array('fi|finnish', 'finnish-iso-8859-1', 'fi'),
00097     'fi-iso-8859-15'    => array('fi|finnish', 'finnish-iso-8859-15', 'fi'),
00098     'fi-utf-8'          => array('fi|finnish', 'finnish-utf-8', 'fi'),
00099     'fr-iso-8859-1'     => array('fr|french', 'french-iso-8859-1', 'fr'),
00100     'fr-iso-8859-15'    => array('fr|french', 'french-iso-8859-15', 'fr'),
00101     'fr-utf-8'          => array('fr|french', 'french-utf-8', 'fr'),
00102     'gl-iso-8859-1'     => array('gl|galician', 'galician-iso-8859-1', 'gl'),
00103     'gl-utf-8'          => array('gl|galician', 'galician-utf-8', 'gl'),
00104     'he-iso-8859-8-i'   => array('he|hebrew', 'hebrew-iso-8859-8-i', 'he'),
00105     'he-utf-8'          => array('he|hebrew', 'hebrew-utf-8', 'he'),
00106     'hi-utf-8'          => array('hi|hindi', 'hindi-utf-8', 'hi'),
00107     'hr-win1250'        => array('hr|croatian', 'croatian-windows-1250', 'hr'),
00108     'hr-iso-8859-2'     => array('hr|croatian', 'croatian-iso-8859-2', 'hr'),
00109     'hr-utf-8'          => array('hr|croatian', 'croatian-utf-8', 'hr'),
00110     'hu-iso-8859-2'     => array('hu|hungarian', 'hungarian-iso-8859-2', 'hu'),
00111     'hu-utf-8'          => array('hu|hungarian', 'hungarian-utf-8', 'hu'),
00112     'id-iso-8859-1'     => array('id|indonesian', 'indonesian-iso-8859-1', 'id'),
00113     'id-utf-8'          => array('id|indonesian', 'indonesian-utf-8', 'id'),
00114     'it-iso-8859-1'     => array('it|italian', 'italian-iso-8859-1', 'it'),
00115     'it-iso-8859-15'    => array('it|italian', 'italian-iso-8859-15', 'it'),
00116     'it-utf-8'          => array('it|italian', 'italian-utf-8', 'it'),
00117     'ja-euc'            => array('ja|japanese', 'japanese-euc', 'ja'),
00118     'ja-sjis'           => array('ja|japanese', 'japanese-sjis', 'ja'),
00119     'ja-utf-8'          => array('ja|japanese', 'japanese-utf-8', 'ja'),
00120     'ko-euc-kr'         => array('ko|korean', 'korean-euc-kr', 'ko'),
00121     'ko-utf-8'          => array('ko|korean', 'korean-utf-8', 'ko'),
00122     'ka-utf-8'          => array('ka|georgian', 'georgian-utf-8', 'ka'),
00123     'lt-win1257'        => array('lt|lithuanian', 'lithuanian-windows-1257', 'lt'),
00124     'lt-utf-8'          => array('lt|lithuanian', 'lithuanian-utf-8', 'lt'),
00125     'lv-win1257'        => array('lv|latvian', 'latvian-windows-1257', 'lv'),
00126     'lv-utf-8'          => array('lv|latvian', 'latvian-utf-8', 'lv'),
00127     'mn-utf-8'          => array('mn|mongolian', 'mongolian-utf-8', 'mn'),
00128     'ms-iso-8859-1'     => array('ms|malay', 'malay-iso-8859-1', 'ms'),
00129     'ms-utf-8'          => array('ms|malay', 'malay-utf-8', 'ms'),
00130     'nl-iso-8859-1'     => array('nl|dutch', 'dutch-iso-8859-1', 'nl'),
00131     'nl-iso-8859-15'    => array('nl|dutch', 'dutch-iso-8859-15', 'nl'),
00132     'nl-utf-8'          => array('nl|dutch', 'dutch-utf-8', 'nl'),
00133     'no-iso-8859-1'     => array('no|norwegian', 'norwegian-iso-8859-1', 'no'),
00134     'no-utf-8'          => array('no|norwegian', 'norwegian-utf-8', 'no'),
00135     'pl-iso-8859-2'     => array('pl|polish', 'polish-iso-8859-2', 'pl'),
00136     'pl-win1250'        => array('pl|polish', 'polish-windows-1250', 'pl'),
00137     'pl-utf-8'          => array('pl|polish', 'polish-utf-8', 'pl'),
00138     'ptbr-iso-8859-1'   => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-iso-8859-1', 'pt-BR'),
00139     'ptbr-utf-8'        => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-utf-8', 'pt-BR'),
00140     'pt-iso-8859-1'     => array('pt|portuguese', 'portuguese-iso-8859-1', 'pt'),
00141     'pt-iso-8859-15'    => array('pt|portuguese', 'portuguese-iso-8859-15', 'pt'),
00142     'pt-utf-8'          => array('pt|portuguese', 'portuguese-utf-8', 'pt'),
00143     'ro-iso-8859-1'     => array('ro|romanian', 'romanian-iso-8859-1', 'ro'),
00144     'ro-utf-8'          => array('ro|romanian', 'romanian-utf-8', 'ro'),
00145     'ru-win1251'        => array('ru|russian', 'russian-windows-1251', 'ru'),
00146     'ru-cp-866'         => array('ru|russian', 'russian-cp-866', 'ru'),
00147     'ru-koi8-r'         => array('ru|russian', 'russian-koi8-r', 'ru'),
00148     'ru-utf-8'          => array('ru|russian', 'russian-utf-8', 'ru'),
00149     'sk-iso-8859-2'     => array('sk|slovak', 'slovak-iso-8859-2', 'sk'),
00150     'sk-win1250'        => array('sk|slovak', 'slovak-windows-1250', 'sk'),
00151     'sk-utf-8'          => array('sk|slovak', 'slovak-utf-8', 'sk'),
00152     'sl-iso-8859-2'     => array('sl|slovenian', 'slovenian-iso-8859-2', 'sl'),
00153     'sl-win1250'        => array('sl|slovenian', 'slovenian-windows-1250', 'sl'),
00154     'sl-utf-8'          => array('sl|slovenian', 'slovenian-utf-8', 'sl'),
00155     'sq-iso-8859-1'     => array('sq|albanian', 'albanian-iso-8859-1', 'sq'),
00156     'sq-utf-8'          => array('sq|albanian', 'albanian-utf-8', 'sq'),
00157     'srlat-win1250'     => array('sr[-_]lat|serbian latin', 'serbian_latin-windows-1250', 'sr-lat'),
00158     'srlat-utf-8'       => array('sr[-_]lat|serbian latin', 'serbian_latin-utf-8', 'sr-lat'),
00159     'srcyr-win1251'     => array('sr|serbian', 'serbian_cyrillic-windows-1251', 'sr'),
00160     'srcyr-utf-8'       => array('sr|serbian', 'serbian_cyrillic-utf-8', 'sr'),
00161     'sv-iso-8859-1'     => array('sv|swedish', 'swedish-iso-8859-1', 'sv'),
00162     'sv-utf-8'          => array('sv|swedish', 'swedish-utf-8', 'sv'),
00163     'th-tis-620'        => array('th|thai', 'thai-tis-620', 'th'),
00164     'th-utf-8'          => array('th|thai', 'thai-utf-8', 'th'),
00165     'tr-iso-8859-9'     => array('tr|turkish', 'turkish-iso-8859-9', 'tr'),
00166     'tr-utf-8'          => array('tr|turkish', 'turkish-utf-8', 'tr'),
00167     'tt-iso-8859-9'     => array('tt|tatarish', 'tatarish-iso-8859-9', 'tt'),
00168     'tt-utf-8'          => array('tt|tatarish', 'tatarish-utf-8', 'tt'),
00169     'uk-win1251'        => array('uk|ukrainian', 'ukrainian-windows-1251', 'uk'),
00170     'uk-utf-8'          => array('uk|ukrainian', 'ukrainian-utf-8', 'uk'),
00171     'zhtw-big5'         => array('zh[-_](tw|hk)|chinese traditional', 'chinese_traditional-big5', 'zh-TW'),
00172     'zhtw-utf-8'        => array('zh[-_](tw|hk)|chinese traditional', 'chinese_traditional-utf-8', 'zh-TW'),
00173     'zh-gb2312'         => array('zh|chinese simplified', 'chinese_simplified-gb2312', 'zh'),
00174     'zh-utf-8'          => array('zh|chinese simplified', 'chinese_simplified-utf-8', 'zh')
00175 );
00176 
00177 
00190 function PMA_langDetect($str = '', $envType = '')
00191 {
00192     global $available_languages;
00193     global $lang;
00194 
00195     foreach ($available_languages AS $key => $value) {
00196         // $envType =  1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable,
00197         //             2 for the 'HTTP_USER_AGENT' one
00198         $expr = $value[0];
00199         if (strpos($expr, '[-_]') === FALSE) {
00200             $expr = str_replace('|', '([-_][[:alpha:]]{2,3})?|', $expr);
00201         }
00202         if (($envType == 1 && eregi('^(' . $expr . ')(;q=[0-9]\\.[0-9])?$', $str))
00203             || ($envType == 2 && eregi('(\(|\[|;[[:space:]])(' . $expr . ')(;|\]|\))', $str))) {
00204             $lang     = $key;
00205             break;
00206         }
00207     }
00208 } // end of the 'PMA_langDetect()' function
00209 
00210 
00211 if (!isset($lang)) {
00212     if (isset($_GET) && !empty($_GET['lang'])) {
00213         $lang = $_GET['lang'];
00214     }
00215     else if (isset($_POST) && !empty($_POST['lang'])) {
00216         $lang = $_POST['lang'];
00217     }
00218     else if (isset($_COOKIE) && !empty($_COOKIE['pma_lang'])) {
00219         $lang = $_COOKIE['pma_lang'];
00220     }
00221 }
00222 
00223 
00228 // compatibility with config.inc.php <= v1.80
00229 if (!isset($cfg['Lang']) && isset($cfgLang)) {
00230     $cfg['Lang']        = $cfgLang;
00231     unset($cfgLang);
00232 }
00233 if (!isset($cfg['DefaultLang']) && isset($cfgDefaultLang)) {
00234     $cfg['DefaultLang'] = $cfgDefaultLang;
00235     unset($cfgLang);
00236 }
00237 
00238 // MySQL charsets map
00239 $mysql_charset_map = array(
00240     'big5'         => 'big5',
00241     'cp-866'       => 'cp866',
00242     'euc-jp'       => 'ujis',
00243     'euc-kr'       => 'euckr',
00244     'gb2312'       => 'gb2312',
00245     'gbk'          => 'gbk',
00246     'iso-8859-1'   => 'latin1',
00247     'iso-8859-2'   => 'latin2',
00248     'iso-8859-7'   => 'greek',
00249     'iso-8859-8'   => 'hebrew',
00250     'iso-8859-8-i' => 'hebrew',
00251     'iso-8859-9'   => 'latin5',
00252     'iso-8859-13'  => 'latin7',
00253     'iso-8859-15'  => 'latin1',
00254     'koi8-r'       => 'koi8r',
00255     'shift_jis'    => 'sjis',
00256     'tis-620'      => 'tis620',
00257     'utf-8'        => 'utf8',
00258     'windows-1250' => 'cp1250',
00259     'windows-1251' => 'cp1251',
00260     'windows-1252' => 'latin1',
00261     'windows-1256' => 'cp1256',
00262     'windows-1257' => 'cp1257',
00263 );
00264 
00265 // Lang forced
00266 if (!empty($cfg['Lang'])) {
00267     $lang = $cfg['Lang'];
00268 }
00269 
00270 // If '$lang' is defined, ensure this is a valid translation
00271 if (!empty($lang) && empty($available_languages[$lang])) {
00272     $lang = '';
00273 }
00274 
00275 // Language is not defined yet :
00276 // 1. try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE
00277 //    variable
00278 if (empty($lang) && !empty($HTTP_ACCEPT_LANGUAGE)) {
00279     $accepted    = explode(',', $HTTP_ACCEPT_LANGUAGE);
00280     $acceptedCnt = count($accepted);
00281     for ($i = 0; $i < $acceptedCnt && empty($lang); $i++) {
00282         PMA_langDetect($accepted[$i], 1);
00283     }
00284 }
00285 // 2. try to findout user's language by checking its HTTP_USER_AGENT variable
00286 if (empty($lang) && !empty($HTTP_USER_AGENT)) {
00287     PMA_langDetect($HTTP_USER_AGENT, 2);
00288 }
00289 
00290 // 3. Didn't catch any valid lang : we use the default settings
00291 if (empty($lang)) {
00292     $lang = $cfg['DefaultLang'];
00293 }
00294 
00295 // 4. Checks whether charset recoding should be allowed or not
00296 $allow_recoding = FALSE; // Default fallback value
00297 if (!isset($convcharset) || empty($convcharset)) {
00298     if (isset($_COOKIE['pma_charset'])) {
00299         $convcharset = $_COOKIE['pma_charset'];
00300     } else {
00301         $convcharset = $cfg['DefaultCharset'];
00302     }
00303 }
00304 
00305 // 5. Defines the associated filename and load the translation
00306 $lang_file = $lang_path . $available_languages[$lang][1] . '.inc.php';
00307 require_once('./' . $lang_file);
00308 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6