home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / select_lang.lib.php < prev    next >
Encoding:
PHP Script  |  2003-12-08  |  12.4 KB  |  267 lines

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