Initial implementation of Gettext based selection.

- Loads list of available languages
- Sets locale
- Loads transitional messages file
This commit is contained in:
Michal Čihař
2010-03-11 17:57:01 +01:00
parent c33c13de97
commit 54c9f24fb8
3 changed files with 1825 additions and 1750 deletions

File diff suppressed because it is too large Load Diff

1636
libraries/messages.inc.php Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -156,6 +156,158 @@ function PMA_langDetect(&$str, $envType)
return false;
} // end of the 'PMA_langDetect()' function
/**
* All the supported languages have to be listed in the array below.
* 1. The key must be the "official" ISO 639 language code and, if required,
* the dialect code. It can also contain some information about the
* charset (see the Russian case).
* 2. The first of the values associated to the key is used in a regular
* expression to find some keywords corresponding to the language inside two
* environment variables.
* These values contain:
* - the "official" ISO language code and, if required, the dialect code
* too ('bu' for Bulgarian, 'fr([-_][[:alpha:]]{2})?' for all French
* dialects, 'zh[-_]tw' for Chinese traditional...), the dialect has to
* be specified first;
* - the '|' character (it means 'OR');
* - the full language name.
* 3. The second value associated to the key is the name of the file to load
* without the 'inc.php' extension.
* 4. The third value associated to the key is the language code as defined by
* the RFC1766.
* 5. The fourth value is its native name in html entities.
*
* Beware that the sorting order (first values associated to keys by
* alphabetical reverse order in the array) is important: 'zh-tw' (chinese
* traditional) must be detected before 'zh' (chinese simplified) for
* example.
*
*/
function PMA_langDetails($lang) {
switch ($lang) {
case 'en':
return array('en|english', 'english-utf-8', 'en', '');
case 'af':
return array('af|afrikaans', 'afrikaans-utf-8', 'af', '');
case 'ar':
return array('ar|arabic', 'arabic-utf-8', 'ar', 'العربية');
case 'az':
return array('az|azerbaijani', 'azerbaijani-utf-8', 'az', 'Azərbaycanca');
case 'bn':
return array('bn|bangla', 'bangla-utf-8', 'bn', '');
case 'be':
return array('be|belarusian', 'belarusian_cyrillic-utf-8', 'be', 'Беларуская');
case 'be@latin':
return array('be[-_]lat|belarusian latin', 'belarusian_latin-utf-8', 'be-lat', 'Biełaruskaja');
case 'bg':
return array('bg|bulgarian', 'bulgarian-utf-8', 'bg', 'Български');
case 'bs':
return array('bs|bosnian', 'bosnian-utf-8', 'bs', 'Bosanski');
case 'ca':
return array('ca|catalan', 'catalan-utf-8', 'ca', 'Català');
case 'cs':
return array('cs|czech', 'czech-utf-8', 'cs', 'Česky');
case 'da':
return array('da|danish', 'danish-utf-8', 'da', 'Dansk');
case 'de':
return array('de|german', 'german-utf-8', 'de', 'Deutsch');
case 'el':
return array('el|greek', 'greek-utf-8', 'el', 'Ελληνικά');
case 'en':
return array('en|english', 'english-utf-8', 'en', '');
case 'en_GB':
return array('en[_-]gb|english (United Kingdom)', 'english-gb-utf-8', 'en', '');
case 'es':
return array('es|spanish', 'spanish-utf-8', 'es', 'Español');
case 'et':
return array('et|estonian', 'estonian-utf-8', 'et', 'Eesti');
case 'eu':
return array('eu|basque', 'basque-utf-8', 'eu', 'Euskara');
case 'fa':
return array('fa|persian', 'persian-utf-8', 'fa', 'فارسی');
case 'fi':
return array('fi|finnish', 'finnish-utf-8', 'fi', 'Suomi');
case 'fr':
return array('fr|french', 'french-utf-8', 'fr', 'Français');
case 'gl':
return array('gl|galician', 'galician-utf-8', 'gl', 'Galego');
case 'he':
return array('he|hebrew', 'hebrew-utf-8', 'he', 'עברית');
case 'hi':
return array('hi|hindi', 'hindi-utf-8', 'hi', 'हिन्दी');
case 'hr':
return array('hr|croatian', 'croatian-utf-8', 'hr', 'Hrvatski');
case 'hu':
return array('hu|hungarian', 'hungarian-utf-8', 'hu', 'Magyar');
case 'id':
return array('id|indonesian', 'indonesian-utf-8', 'id', 'Bahasa Indonesia');
case 'it':
return array('it|italian', 'italian-utf-8', 'it', 'Italiano');
case 'jp':
return array('jp|japanese', 'japanese-utf-8', 'jp', '日本語');
case 'ko':
return array('ko|korean', 'korean-utf-8', 'ko', '한국어');
case 'ka':
return array('ka|georgian', 'georgian-utf-8', 'ka', 'ქართული');
case 'lt':
return array('lt|lithuanian', 'lithuanian-utf-8', 'lt', 'Lietuvių');
case 'lv':
return array('lv|latvian', 'latvian-utf-8', 'lv', 'Latviešu');
case 'mk':
return array('mk|macedonian', 'macedonian_cyrillic-utf-8', 'mk', 'Macedonian');
case 'mn':
return array('mn|mongolian', 'mongolian-utf-8', 'mn', 'Монгол');
case 'ms':
return array('ms|malay', 'malay-utf-8', 'ms', 'Bahasa Melayu');
case 'nl':
return array('nl|dutch', 'dutch-utf-8', 'nl', 'Nederlands');
case 'no':
return array('no|norwegian', 'norwegian-utf-8', 'no', 'Norsk');
case 'pl':
return array('pl|polish', 'polish-utf-8', 'pl', 'Polski');
case 'pt_BR':
return array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-utf-8', 'pt-BR', 'Português');
case 'pt':
return array('pt|portuguese', 'portuguese-utf-8', 'pt', 'Português');
case 'ro':
return array('ro|romanian', 'romanian-utf-8', 'ro', 'Română');
case 'ru':
return array('ru|russian', 'russian-utf-8', 'ru', 'Русский');
case 'si':
return array('si|sinhala', 'sinhala-utf-8', 'si', 'සිංහල');
case 'sk':
return array('sk|slovak', 'slovak-utf-8', 'sk', 'Slovenčina');
case 'sl':
return array('sl|slovenian', 'slovenian-utf-8', 'sl', 'Slovenščina');
case 'sq':
return array('sq|albanian', 'albanian-utf-8', 'sq', 'Shqip');
case 'sr@latin':
return array('sr[-_]lat|serbian latin', 'serbian_latin-utf-8', 'sr-lat', 'Srpski');
case 'sr':
return array('sr|serbian', 'serbian_cyrillic-utf-8', 'sr', 'Српски');
case 'sv':
return array('sv|swedish', 'swedish-utf-8', 'sv', 'Svenska');
case 'th':
return array('th|thai', 'thai-utf-8', 'th', 'ภาษาไทย');
case 'tr':
return array('tr|turkish', 'turkish-utf-8', 'tr', 'Türkçe');
case 'tt':
return array('tt|tatarish', 'tatarish-utf-8', 'tt', 'Tatarça');
case 'uk':
return array('uk|ukrainian', 'ukrainian-utf-8', 'uk', 'Українська');
case 'uz@latin':
return array('uz[-_]lat|uzbek-latin', 'uzbek_latin-utf-8', 'uz-lat', 'O‘zbekcha');
case 'uz':
return array('uz[-_]cyr|uzbek-cyrillic', 'uzbek_cyrillic-utf-8', 'uz-cyr', 'Ўзбекча');
case 'zh_TW':
return array('zh[-_](tw|hk)|chinese traditional', 'chinese_traditional-utf-8', 'zh-TW', '中文');
case 'zh_CN':
return array('zh|chinese simplified', 'chinese_simplified-utf-8', 'zh', '中文');
}
return array($lang, $lang, $lang, '');
}
/**
* Returns list of languages supported by phpMyAdmin
*
@@ -163,104 +315,47 @@ function PMA_langDetect(&$str, $envType)
*/
function PMA_langList()
{
/**
* All the supported languages have to be listed in the array below.
* 1. The key must be the "official" ISO 639 language code and, if required,
* the dialect code. It can also contain some information about the
* charset (see the Russian case).
* 2. The first of the values associated to the key is used in a regular
* expression to find some keywords corresponding to the language inside two
* environment variables.
* These values contain:
* - the "official" ISO language code and, if required, the dialect code
* too ('bu' for Bulgarian, 'fr([-_][[:alpha:]]{2})?' for all French
* dialects, 'zh[-_]tw' for Chinese traditional...), the dialect has to
* be specified first;
* - the '|' character (it means 'OR');
* - the full language name.
* 3. The second value associated to the key is the name of the file to load
* without the 'inc.php' extension.
* 4. The third value associated to the key is the language code as defined by
* the RFC1766.
* 5. The fourth value is its native name in html entities.
*
* Beware that the sorting order (first values associated to keys by
* alphabetical reverse order in the array) is important: 'zh-tw' (chinese
* traditional) must be detected before 'zh' (chinese simplified) for
* example.
*
*/
return array(
'af-utf-8' => array('af|afrikaans', 'afrikaans-utf-8', 'af', ''),
'ar-utf-8' => array('ar|arabic', 'arabic-utf-8', 'ar', 'العربية'),
'az-utf-8' => array('az|azerbaijani', 'azerbaijani-utf-8', 'az', 'Azərbaycanca'),
'bn-utf-8' => array('bn|bangla', 'bangla-utf-8', 'bn', ''),
'becyr-utf-8' => array('be|belarusian', 'belarusian_cyrillic-utf-8', 'be', 'Беларуская'),
'belat-utf-8' => array('be[-_]lat|belarusian latin', 'belarusian_latin-utf-8', 'be-lat', 'Biełaruskaja'),
'bg-utf-8' => array('bg|bulgarian', 'bulgarian-utf-8', 'bg', 'Български'),
'bs-utf-8' => array('bs|bosnian', 'bosnian-utf-8', 'bs', 'Bosanski'),
'ca-utf-8' => array('ca|catalan', 'catalan-utf-8', 'ca', 'Català'),
'cs-utf-8' => array('cs|czech', 'czech-utf-8', 'cs', 'Česky'),
'da-utf-8' => array('da|danish', 'danish-utf-8', 'da', 'Dansk'),
'de-utf-8' => array('de|german', 'german-utf-8', 'de', 'Deutsch'),
'el-utf-8' => array('el|greek', 'greek-utf-8', 'el', 'Ελληνικά'),
'en-utf-8' => array('en|english', 'english-utf-8', 'en', ''),
'en-gb-utf-8' => array('en[_-]gb|english (United Kingdom)', 'english-gb-utf-8', 'en', ''),
'es-utf-8' => array('es|spanish', 'spanish-utf-8', 'es', 'Español'),
'et-utf-8' => array('et|estonian', 'estonian-utf-8', 'et', 'Eesti'),
'eu-utf-8' => array('eu|basque', 'basque-utf-8', 'eu', 'Euskara'),
'fa-utf-8' => array('fa|persian', 'persian-utf-8', 'fa', 'فارسی'),
'fi-utf-8' => array('fi|finnish', 'finnish-utf-8', 'fi', 'Suomi'),
'fr-utf-8' => array('fr|french', 'french-utf-8', 'fr', 'Français'),
'gl-utf-8' => array('gl|galician', 'galician-utf-8', 'gl', 'Galego'),
'he-utf-8' => array('he|hebrew', 'hebrew-utf-8', 'he', 'עברית'),
'hi-utf-8' => array('hi|hindi', 'hindi-utf-8', 'hi', 'हिन्दी'),
'hr-utf-8' => array('hr|croatian', 'croatian-utf-8', 'hr', 'Hrvatski'),
'hu-utf-8' => array('hu|hungarian', 'hungarian-utf-8', 'hu', 'Magyar'),
'id-utf-8' => array('id|indonesian', 'indonesian-utf-8', 'id', 'Bahasa Indonesia'),
'it-utf-8' => array('it|italian', 'italian-utf-8', 'it', 'Italiano'),
'ja-utf-8' => array('ja|japanese', 'japanese-utf-8', 'ja', '日本語'),
'ko-utf-8' => array('ko|korean', 'korean-utf-8', 'ko', '한국어'),
'ka-utf-8' => array('ka|georgian', 'georgian-utf-8', 'ka', 'ქართული'),
'lt-utf-8' => array('lt|lithuanian', 'lithuanian-utf-8', 'lt', 'Lietuvių'),
'lv-utf-8' => array('lv|latvian', 'latvian-utf-8', 'lv', 'Latviešu'),
'mkcyr-utf-8' => array('mk|macedonian', 'macedonian_cyrillic-utf-8', 'mk', 'Macedonian'),
'mn-utf-8' => array('mn|mongolian', 'mongolian-utf-8', 'mn', 'Монгол'),
'ms-utf-8' => array('ms|malay', 'malay-utf-8', 'ms', 'Bahasa Melayu'),
'nl-utf-8' => array('nl|dutch', 'dutch-utf-8', 'nl', 'Nederlands'),
'no-utf-8' => array('no|norwegian', 'norwegian-utf-8', 'no', 'Norsk'),
'pl-utf-8' => array('pl|polish', 'polish-utf-8', 'pl', 'Polski'),
'ptbr-utf-8' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-utf-8', 'pt-BR', 'Português'),
'pt-utf-8' => array('pt|portuguese', 'portuguese-utf-8', 'pt', 'Português'),
'ro-utf-8' => array('ro|romanian', 'romanian-utf-8', 'ro', 'Română'),
'ru-utf-8' => array('ru|russian', 'russian-utf-8', 'ru', 'Русский'),
'si-utf-8' => array('si|sinhala', 'sinhala-utf-8', 'si', 'සිංහල'),
'sk-utf-8' => array('sk|slovak', 'slovak-utf-8', 'sk', 'Slovenčina'),
'sl-utf-8' => array('sl|slovenian', 'slovenian-utf-8', 'sl', 'Slovenščina'),
'sq-utf-8' => array('sq|albanian', 'albanian-utf-8', 'sq', 'Shqip'),
'srlat-utf-8' => array('sr[-_]lat|serbian latin', 'serbian_latin-utf-8', 'sr-lat', 'Srpski'),
'srcyr-utf-8' => array('sr|serbian', 'serbian_cyrillic-utf-8', 'sr', 'Српски'),
'sv-utf-8' => array('sv|swedish', 'swedish-utf-8', 'sv', 'Svenska'),
'th-utf-8' => array('th|thai', 'thai-utf-8', 'th', 'ภาษาไทย'),
'tr-utf-8' => array('tr|turkish', 'turkish-utf-8', 'tr', 'Türkçe'),
'tt-utf-8' => array('tt|tatarish', 'tatarish-utf-8', 'tt', 'Tatarça'),
'uk-utf-8' => array('uk|ukrainian', 'ukrainian-utf-8', 'uk', 'Українська'),
'uzlat-utf-8' => array('uz[-_]lat|uzbek-latin', 'uzbek_latin-utf-8', 'uz-lat', 'O‘zbekcha'),
'uzcyr-utf-8' => array('uz[-_]cyr|uzbek-cyrillic', 'uzbek_cyrillic-utf-8', 'uz-cyr', 'Ўзбекча'),
'zhtw-utf-8' => array('zh[-_](tw|hk)|chinese traditional', 'chinese_traditional-utf-8', 'zh-TW', '中文'),
'zh-utf-8' => array('zh|chinese simplified', 'chinese_simplified-utf-8', 'zh', '中文'),
);
/* We can always speak English */
$result = array('en-utf-8' => PMA_langDetails('en'));
/* Open the directory */
$handle = @opendir($GLOBALS['lang_path']);
if ($handle === FALSE) {
trigger_error('phpMyAdmin: path not found: '
. $GLOBALS['lang_path'] . ', check your language directory.',
E_USER_WARNING);
return $result;
}
/* Process all files */
while (FALSE !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && file_exists($GLOBALS['lang_path'] . '/' . $file . '/LC_MESSAGES/phpmyadmin.mo')) {
$result[$file] = PMA_langDetails($file);
}
}
/* Close the handle */
closedir($handle);
return $result;
}
/**
* @global string path to the translations directory
*/
$GLOBALS['lang_path'] = './lang/';
$GLOBALS['lang_path'] = './locale/';
define('LOCALE_DIR', realpath($GLOBALS['lang_path']));
define('DEFAULT_LOCALE', 'en_US');
/**
* Load gettext functions.
*/
require_once './libraries/php-gettext/gettext.inc';
/**
* @global string interface language
*/
$GLOBALS['lang'] = 'en-utf-8';
$GLOBALS['lang'] = 'en';
/**
* @global boolean whether loading lang from cfg failed
*/
@@ -297,28 +392,6 @@ if (! empty($GLOBALS['cfg']['FilterLanguages'])) {
unset($key, $val, $new_lang);
}
/**
* first check for lang dir exists
*/
if (! is_dir($GLOBALS['lang_path'])) {
// language directory not found
trigger_error('phpMyAdmin-ERROR: path not found: '
. $GLOBALS['lang_path'] . ', check your language directory.',
E_USER_WARNING);
// and tell the user
PMA_fatalError('path to languages is invalid: ' . $GLOBALS['lang_path']);
}
/**
* check for language files
*/
foreach ($GLOBALS['available_languages'] as $each_lang_key => $each_lang) {
if (! file_exists($GLOBALS['lang_path'] . $each_lang[1] . '.inc.php')) {
unset($GLOBALS['available_languages'][$each_lang_key]);
}
}
unset($each_lang_key, $each_lang);
/**
* @global array MySQL charsets map
*/
@@ -376,9 +449,11 @@ if (! PMA_langCheck()) {
}
}
// Defines the associated filename and load the translation
$lang_file = $GLOBALS['lang_path'] . $GLOBALS['available_languages'][$GLOBALS['lang']][1] . '.inc.php';
require_once $lang_file;
// Set locale
T_setlocale(LC_MESSAGES, $GLOBALS['lang']);
// Load messages
require_once './libraries/messages.inc.php';
// now, that we have loaded the language strings we can send the errors
if ($GLOBALS['lang_failed_cfg']) {