12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001 |
- <?php
- /* vim: set expandtab sw=4 ts=4 sts=4: */
- /**
- * Hold the PhpMyAdmin\LanguageManager class
- *
- * @package PhpMyAdmin
- */
- namespace PhpMyAdmin;
- use PhpMyAdmin\Core;
- use PhpMyAdmin\Language;
- use PhpMyAdmin\Template;
- use PhpMyAdmin\Url;
- use PhpMyAdmin\Util;
- /**
- * Language selection manager
- *
- * @package PhpMyAdmin
- */
- class LanguageManager
- {
- /**
- * @var array Definition data for languages
- *
- * Each member contains:
- * - Language code
- * - English language name
- * - Native language name
- * - Match regullar expression
- * - MySQL locale
- */
- private static $_language_data = array(
- 'af' => array(
- 'af',
- 'Afrikaans',
- '',
- 'af|afrikaans',
- '',
- ),
- 'am' => array(
- 'am',
- 'Amharic',
- 'አማርኛ',
- 'am|amharic',
- '',
- ),
- 'ar' => array(
- 'ar',
- 'Arabic',
- 'العربية',
- 'ar|arabic',
- 'ar_AE',
- ),
- 'ar_ly' => array(
- 'ar_LY',
- 'Arabic (Libya)',
- 'ليبي',
- 'ar[_-]ly|arabic (libya)|libian arabic',
- 'ar_LY',
- ),
- 'az' => array(
- 'az',
- 'Azerbaijani',
- 'Azərbaycanca',
- 'az|azerbaijani',
- '',
- ),
- 'bn' => array(
- 'bn',
- 'Bangla',
- 'বাংলা',
- 'bn|bangla',
- '',
- ),
- 'be' => array(
- 'be',
- 'Belarusian',
- 'Беларуская',
- 'be|belarusian',
- 'be_BY',
- ),
- 'be@latin' => array(
- 'be@latin',
- 'Belarusian (latin)',
- 'Biełaruskaja',
- 'be[-_]lat|be@latin|belarusian latin',
- '',
- ),
- 'ber' => array(
- 'ber',
- 'Berber',
- 'Tamaziɣt',
- 'ber|berber',
- '',
- ),
- 'bg' => array(
- 'bg',
- 'Bulgarian',
- 'Български',
- 'bg|bulgarian',
- 'bg_BG',
- ),
- 'bs' => array(
- 'bs',
- 'Bosnian',
- 'Bosanski',
- 'bs|bosnian',
- '',
- ),
- 'br' => array(
- 'br',
- 'Breton',
- 'Brezhoneg',
- 'br|breton',
- '',
- ),
- 'brx' => array(
- 'brx',
- 'Bodo',
- 'बड़ो',
- 'brx|bodo',
- '',
- ),
- 'ca' => array(
- 'ca',
- 'Catalan',
- 'Català',
- 'ca|catalan',
- 'ca_ES',
- ),
- 'ckb' => array(
- 'ckb',
- 'Sorani',
- 'سۆرانی',
- 'ckb|sorani',
- '',
- ),
- 'cs' => array(
- 'cs',
- 'Czech',
- 'Čeština',
- 'cs|czech',
- 'cs_CZ',
- ),
- 'cy' => array(
- 'cy',
- 'Welsh',
- 'Cymraeg',
- 'cy|welsh',
- '',
- ),
- 'da' => array(
- 'da',
- 'Danish',
- 'Dansk',
- 'da|danish',
- 'da_DK',
- ),
- 'de' => array(
- 'de',
- 'German',
- 'Deutsch',
- 'de|german',
- 'de_DE',
- ),
- 'el' => array(
- 'el',
- 'Greek',
- 'Ελληνικά',
- 'el|greek',
- '',
- ),
- 'en' => array(
- 'en',
- 'English',
- '',
- 'en|english',
- 'en_US',
- ),
- 'en_gb' => array(
- 'en_GB',
- 'English (United Kingdom)',
- '',
- 'en[_-]gb|english (United Kingdom)',
- 'en_GB',
- ),
- 'eo' => array(
- 'eo',
- 'Esperanto',
- 'Esperanto',
- 'eo|esperanto',
- '',
- ),
- 'es' => array(
- 'es',
- 'Spanish',
- 'Español',
- 'es|spanish',
- 'es_ES',
- ),
- 'et' => array(
- 'et',
- 'Estonian',
- 'Eesti',
- 'et|estonian',
- 'et_EE',
- ),
- 'eu' => array(
- 'eu',
- 'Basque',
- 'Euskara',
- 'eu|basque',
- 'eu_ES',
- ),
- 'fa' => array(
- 'fa',
- 'Persian',
- 'فارسی',
- 'fa|persian',
- '',
- ),
- 'fi' => array(
- 'fi',
- 'Finnish',
- 'Suomi',
- 'fi|finnish',
- 'fi_FI',
- ),
- 'fil' => array(
- 'fil',
- 'Filipino',
- 'Pilipino',
- 'fil|filipino',
- '',
- ),
- 'fr' => array(
- 'fr',
- 'French',
- 'Français',
- 'fr|french',
- 'fr_FR',
- ),
- 'fy' => array(
- 'fy',
- 'Frisian',
- 'Frysk',
- 'fy|frisian',
- '',
- ),
- 'gl' => array(
- 'gl',
- 'Galician',
- 'Galego',
- 'gl|galician',
- 'gl_ES',
- ),
- 'gu' => array(
- 'gu',
- 'Gujarati',
- 'ગુજરાતી',
- 'gu|gujarati',
- 'gu_IN',
- ),
- 'he' => array(
- 'he',
- 'Hebrew',
- 'עברית',
- 'he|hebrew',
- 'he_IL',
- ),
- 'hi' => array(
- 'hi',
- 'Hindi',
- 'हिन्दी',
- 'hi|hindi',
- 'hi_IN',
- ),
- 'hr' => array(
- 'hr',
- 'Croatian',
- 'Hrvatski',
- 'hr|croatian',
- 'hr_HR',
- ),
- 'hu' => array(
- 'hu',
- 'Hungarian',
- 'Magyar',
- 'hu|hungarian',
- 'hu_HU',
- ),
- 'hy' => array(
- 'hy',
- 'Armenian',
- 'Հայերէն',
- 'hy|armenian',
- '',
- ),
- 'ia' => array(
- 'ia',
- 'Interlingua',
- '',
- 'ia|interlingua',
- '',
- ),
- 'id' => array(
- 'id',
- 'Indonesian',
- 'Bahasa Indonesia',
- 'id|indonesian',
- 'id_ID',
- ),
- 'ig' => array(
- 'ig',
- 'Igbo',
- 'Asụsụ Igbo',
- 'ig|igbo',
- '',
- ),
- 'it' => array(
- 'it',
- 'Italian',
- 'Italiano',
- 'it|italian',
- 'it_IT',
- ),
- 'ja' => array(
- 'ja',
- 'Japanese',
- '日本語',
- 'ja|japanese',
- 'ja_JP',
- ),
- 'ko' => array(
- 'ko',
- 'Korean',
- '한국어',
- 'ko|korean',
- 'ko_KR',
- ),
- 'ka' => array(
- 'ka',
- 'Georgian',
- 'ქართული',
- 'ka|georgian',
- '',
- ),
- 'kab' => array(
- 'kab',
- 'Kabylian',
- 'Taqbaylit',
- 'kab|kabylian',
- '',
- ),
- 'kk' => array(
- 'kk',
- 'Kazakh',
- 'Қазақ',
- 'kk|kazakh',
- '',
- ),
- 'km' => array(
- 'km',
- 'Khmer',
- 'ខ្មែរ',
- 'km|khmer',
- '',
- ),
- 'kn' => array(
- 'kn',
- 'Kannada',
- 'ಕನ್ನಡ',
- 'kn|kannada',
- '',
- ),
- 'ksh' => array(
- 'ksh',
- 'Colognian',
- 'Kölsch',
- 'ksh|colognian',
- '',
- ),
- 'ku' => array(
- 'ku',
- 'Kurdish',
- 'کوردی',
- 'ku|kurdish',
- '',
- ),
- 'ky' => array(
- 'ky',
- 'Kyrgyz',
- 'Кыргызча',
- 'ky|kyrgyz',
- '',
- ),
- 'li' => array(
- 'li',
- 'Limburgish',
- 'Lèmbörgs',
- 'li|limburgish',
- '',
- ),
- 'lt' => array(
- 'lt',
- 'Lithuanian',
- 'Lietuvių',
- 'lt|lithuanian',
- 'lt_LT',
- ),
- 'lv' => array(
- 'lv',
- 'Latvian',
- 'Latviešu',
- 'lv|latvian',
- 'lv_LV',
- ),
- 'mk' => array(
- 'mk',
- 'Macedonian',
- 'Macedonian',
- 'mk|macedonian',
- 'mk_MK',
- ),
- 'ml' => array(
- 'ml',
- 'Malayalam',
- 'Malayalam',
- 'ml|malayalam',
- '',
- ),
- 'mn' => array(
- 'mn',
- 'Mongolian',
- 'Монгол',
- 'mn|mongolian',
- 'mn_MN',
- ),
- 'ms' => array(
- 'ms',
- 'Malay',
- 'Bahasa Melayu',
- 'ms|malay',
- 'ms_MY',
- ),
- 'my' => array(
- 'my',
- 'Burmese',
- 'မြန်မာ',
- 'my|burmese',
- '',
- ),
- 'ne' => array(
- 'ne',
- 'Nepali',
- 'नेपाली',
- 'ne|nepali',
- '',
- ),
- 'nb' => array(
- 'nb',
- 'Norwegian',
- 'Norsk',
- 'nb|norwegian',
- 'nb_NO',
- ),
- 'nn' => array(
- 'nn',
- 'Norwegian Nynorsk',
- 'Nynorsk',
- 'nn|nynorsk',
- 'nn_NO',
- ),
- 'nl' => array(
- 'nl',
- 'Dutch',
- 'Nederlands',
- 'nl|dutch',
- 'nl_NL',
- ),
- 'pa' => array(
- 'pa',
- 'Punjabi',
- 'ਪੰਜਾਬੀ',
- 'pa|punjabi',
- '',
- ),
- 'pl' => array(
- 'pl',
- 'Polish',
- 'Polski',
- 'pl|polish',
- 'pl_PL',
- ),
- 'pt_br' => array(
- 'pt_BR',
- 'Brazilian Portuguese',
- 'Português',
- 'pt[-_]br|brazilian portuguese',
- 'pt_BR',
- ),
- 'pt' => array(
- 'pt',
- 'Portuguese',
- 'Português',
- 'pt|portuguese',
- 'pt_PT',
- ),
- 'rcf' => array(
- 'rcf',
- 'Réunion Creole',
- 'Kréol',
- 'rcf|creole (reunion)',
- '',
- ),
- 'ro' => array(
- 'ro',
- 'Romanian',
- 'Română',
- 'ro|romanian',
- 'ro_RO',
- ),
- 'ru' => array(
- 'ru',
- 'Russian',
- 'Русский',
- 'ru|russian',
- 'ru_RU',
- ),
- 'si' => array(
- 'si',
- 'Sinhala',
- 'සිංහල',
- 'si|sinhala',
- '',
- ),
- 'sk' => array(
- 'sk',
- 'Slovak',
- 'Slovenčina',
- 'sk|slovak',
- 'sk_SK',
- ),
- 'sl' => array(
- 'sl',
- 'Slovenian',
- 'Slovenščina',
- 'sl|slovenian',
- 'sl_SI',
- ),
- 'sq' => array(
- 'sq',
- 'Albanian',
- 'Shqip',
- 'sq|albanian',
- 'sq_AL',
- ),
- 'sr@latin' => array(
- 'sr@latin',
- 'Serbian (latin)',
- 'Srpski',
- 'sr[-_]lat|sr@latin|serbian latin',
- 'sr_YU',
- ),
- 'sr' => array(
- 'sr',
- 'Serbian',
- 'Српски',
- 'sr|serbian',
- 'sr_YU',
- ),
- 'sv' => array(
- 'sv',
- 'Swedish',
- 'Svenska',
- 'sv|swedish',
- 'sv_SE',
- ),
- 'ta' => array(
- 'ta',
- 'Tamil',
- 'தமிழ்',
- 'ta|tamil',
- 'ta_IN',
- ),
- 'te' => array(
- 'te',
- 'Telugu',
- 'తెలుగు',
- 'te|telugu',
- 'te_IN',
- ),
- 'th' => array(
- 'th',
- 'Thai',
- 'ภาษาไทย',
- 'th|thai',
- 'th_TH',
- ),
- 'tk' => array(
- 'tk',
- 'Turkmen',
- 'Türkmençe',
- 'tk|turkmen',
- '',
- ),
- 'tr' => array(
- 'tr',
- 'Turkish',
- 'Türkçe',
- 'tr|turkish',
- 'tr_TR',
- ),
- 'tt' => array(
- 'tt',
- 'Tatarish',
- 'Tatarça',
- 'tt|tatarish',
- '',
- ),
- 'tzm' => array(
- 'tzm',
- 'Central Atlas Tamazight',
- 'Tamaziɣt',
- 'tzm|central atlas tamazight',
- '',
- ),
- 'ug' => array(
- 'ug',
- 'Uyghur',
- 'ئۇيغۇرچە',
- 'ug|uyghur',
- '',
- ),
- 'uk' => array(
- 'uk',
- 'Ukrainian',
- 'Українська',
- 'uk|ukrainian',
- 'uk_UA',
- ),
- 'ur' => array(
- 'ur',
- 'Urdu',
- 'اُردوُ',
- 'ur|urdu',
- 'ur_PK',
- ),
- 'uz@latin' => array(
- 'uz@latin',
- 'Uzbek (latin)',
- 'O‘zbekcha',
- 'uz[-_]lat|uz@latin|uzbek-latin',
- '',
- ),
- 'uz' => array(
- 'uz',
- 'Uzbek (cyrillic)',
- 'Ўзбекча',
- 'uz[-_]cyr|uz@cyrillic|uzbek-cyrillic',
- '',
- ),
- 'vi' => array(
- 'vi',
- 'Vietnamese',
- 'Tiếng Việt',
- 'vi|vietnamese',
- 'vi_VN',
- ),
- 'vls' => array(
- 'vls',
- 'Flemish',
- 'West-Vlams',
- 'vls|flemish',
- '',
- ),
- 'zh_tw' => array(
- 'zh_TW',
- 'Chinese traditional',
- '中文',
- 'zh[-_](tw|hk)|chinese traditional',
- 'zh_TW',
- ),
- // only TW and HK use traditional Chinese while others (CN, SG, MY)
- // use simplified Chinese
- 'zh_cn' => array(
- 'zh_CN',
- 'Chinese simplified',
- '中文',
- 'zh(?![-_](tw|hk))([-_][[:alpha:]]{2,3})?|chinese simplified',
- 'zh_CN',
- ),
- );
- private $_available_locales;
- private $_available_languages;
- private $_lang_failed_cfg;
- private $_lang_failed_cookie;
- private $_lang_failed_request;
- private static $instance;
- /**
- * Returns LanguageManager singleton
- *
- * @return LanguageManager
- */
- public static function getInstance()
- {
- if (self::$instance === null) {
- self::$instance = new LanguageManager;
- }
- return self::$instance;
- }
- /**
- * Returns list of available locales
- *
- * @return array
- */
- public function listLocaleDir()
- {
- $result = array('en');
- /* Check for existing directory */
- if (!is_dir(LOCALE_PATH)) {
- return $result;
- }
- /* Open the directory */
- $handle = @opendir(LOCALE_PATH);
- /* This can happen if the kit is English-only */
- if ($handle === false) {
- return $result;
- }
- /* Process all files */
- while (false !== ($file = readdir($handle))) {
- $path = LOCALE_PATH
- . '/' . $file
- . '/LC_MESSAGES/phpmyadmin.mo';
- if ($file != "."
- && $file != ".."
- && @file_exists($path)
- ) {
- $result[] = $file;
- }
- }
- /* Close the handle */
- closedir($handle);
- return $result;
- }
- /**
- * Returns (cached) list of all available locales
- *
- * @return array of strings
- */
- public function availableLocales()
- {
- if (! $this->_available_locales) {
- if (! isset($GLOBALS['PMA_Config']) || empty($GLOBALS['PMA_Config']->get('FilterLanguages'))) {
- $this->_available_locales = $this->listLocaleDir();
- } else {
- $this->_available_locales = preg_grep(
- '@' . $GLOBALS['PMA_Config']->get('FilterLanguages') . '@',
- $this->listLocaleDir()
- );
- }
- }
- return $this->_available_locales;
- }
- /**
- * Checks whether there are some languages available
- *
- * @return boolean
- */
- public function hasChoice()
- {
- return count($this->availableLanguages()) > 1;
- }
- /**
- * Returns (cached) list of all available languages
- *
- * @return array of Language objects
- */
- public function availableLanguages()
- {
- if (! $this->_available_languages) {
- $this->_available_languages = array();
- foreach($this->availableLocales() as $lang) {
- $lang = strtolower($lang);
- if (isset($this::$_language_data[$lang])) {
- $data = $this::$_language_data[$lang];
- $this->_available_languages[$lang] = new Language(
- $data[0],
- $data[1],
- $data[2],
- $data[3],
- $data[4]
- );
- } else {
- $this->_available_languages[$lang] = new Language(
- $lang,
- ucfirst($lang),
- ucfirst($lang),
- $lang,
- ''
- );
- }
- }
- }
- return $this->_available_languages;
- }
- /**
- * Returns (cached) list of all available languages sorted
- * by name
- *
- * @return array of Language objects
- */
- public function sortedLanguages()
- {
- $this->availableLanguages();
- uasort($this->_available_languages, function($a, $b)
- {
- return $a->cmp($b);
- }
- );
- return $this->_available_languages;
- }
- /**
- * Return Language object for given code
- *
- * @param string $code Language code
- *
- * @return object|false Language object or false on failure
- */
- public function getLanguage($code)
- {
- $code = strtolower($code);
- $langs = $this->availableLanguages();
- if (isset($langs[$code])) {
- return $langs[$code];
- }
- return false;
- }
- /**
- * Return currently active Language object
- *
- * @return object Language object
- */
- public function getCurrentLanguage()
- {
- return $this->_available_languages[strtolower($GLOBALS['lang'])];
- }
- /**
- * Activates language based on configuration, user preferences or
- * browser
- *
- * @return Language
- */
- public function selectLanguage()
- {
- // check forced language
- if (! empty($GLOBALS['PMA_Config']->get('Lang'))) {
- $lang = $this->getLanguage($GLOBALS['PMA_Config']->get('Lang'));
- if ($lang !== false) {
- return $lang;
- }
- $this->_lang_failed_cfg = true;
- }
- // Don't use REQUEST in following code as it might be confused by cookies
- // with same name. Check user requested language (POST)
- if (! empty($_POST['lang'])) {
- $lang = $this->getLanguage($_POST['lang']);
- if ($lang !== false) {
- return $lang;
- }
- $this->_lang_failed_request = true;
- }
- // check user requested language (GET)
- if (! empty($_GET['lang'])) {
- $lang = $this->getLanguage($_GET['lang']);
- if ($lang !== false) {
- return $lang;
- }
- $this->_lang_failed_request = true;
- }
- // check previous set language
- if (! empty($GLOBALS['PMA_Config']->getCookie('pma_lang'))) {
- $lang = $this->getLanguage($GLOBALS['PMA_Config']->getCookie('pma_lang'));
- if ($lang !== false) {
- return $lang;
- }
- $this->_lang_failed_cookie = true;
- }
- $langs = $this->availableLanguages();
- // try to find out user's language by checking its HTTP_ACCEPT_LANGUAGE variable;
- $accepted_languages = Core::getenv('HTTP_ACCEPT_LANGUAGE');
- if ($accepted_languages) {
- foreach (explode(',', $accepted_languages) as $header) {
- foreach ($langs as $language) {
- if ($language->matchesAcceptLanguage($header)) {
- return $language;
- }
- }
- }
- }
- // try to find out user's language by checking its HTTP_USER_AGENT variable
- $user_agent = Core::getenv('HTTP_USER_AGENT');
- if (! empty($user_agent)) {
- foreach ($langs as $language) {
- if ($language->matchesUserAgent($user_agent)) {
- return $language;
- }
- }
- }
- // Didn't catch any valid lang : we use the default settings
- if (isset($langs[$GLOBALS['PMA_Config']->get('DefaultLang')])) {
- return $langs[$GLOBALS['PMA_Config']->get('DefaultLang')];
- }
- // Fallback to English
- return $langs['en'];
- }
- /**
- * Displays warnings about invalid languages. This needs to be postponed
- * to show messages at time when language is initialized.
- *
- * @return void
- */
- public function showWarnings()
- {
- // now, that we have loaded the language strings we can send the errors
- if ($this->_lang_failed_cfg
- || $this->_lang_failed_cookie
- || $this->_lang_failed_request
- ) {
- trigger_error(
- __('Ignoring unsupported language code.'),
- E_USER_ERROR
- );
- }
- }
- /**
- * Returns HTML code for the language selector
- *
- * @param boolean $use_fieldset whether to use fieldset for selection
- * @param boolean $show_doc whether to show documentation links
- *
- * @return string
- *
- * @access public
- */
- public function getSelectorDisplay($use_fieldset = false, $show_doc = true)
- {
- $_form_params = array(
- 'db' => $GLOBALS['db'],
- 'table' => $GLOBALS['table'],
- );
- // For non-English, display "Language" with emphasis because it's
- // not a proper word in the current language; we show it to help
- // people recognize the dialog
- $language_title = __('Language')
- . (__('Language') != 'Language' ? ' - <em>Language</em>' : '');
- if ($show_doc) {
- $language_title .= Util::showDocu('faq', 'faq7-2');
- }
- $available_languages = $this->sortedLanguages();
- return Template::get('select_lang')->render(
- array(
- 'language_title' => $language_title,
- 'use_fieldset' => $use_fieldset,
- 'available_languages' => $available_languages,
- '_form_params' => $_form_params,
- )
- );
- }
- }
|