home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / select_lang.lib.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  22.5 KB  |  458 lines

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