diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/controllers/l10n_client.php | 8 | ||||
-rw-r--r-- | core/helpers/locale.php | 207 | ||||
-rw-r--r-- | core/libraries/I18n.php | 33 | ||||
-rw-r--r-- | core/tests/I18n_Test.php | 2 |
4 files changed, 124 insertions, 126 deletions
diff --git a/core/controllers/l10n_client.php b/core/controllers/l10n_client.php index b1d37849..41e05c98 100644 --- a/core/controllers/l10n_client.php +++ b/core/controllers/l10n_client.php @@ -24,8 +24,8 @@ class L10n_Client_Controller extends Controller { $input = Input::instance(); $message = $input->post("l10n-message-source"); $translation = $input->post("l10n-edit-target"); - $key = I18n::getMessageKey($message); - $locale = I18n::instance()->getLocale(); + $key = I18n::get_message_key($message); + $locale = I18n::instance()->locale(); $entry = ORM::factory("outgoing_translation") ->where(array("key" => $key, @@ -78,7 +78,7 @@ class L10n_Client_Controller extends Controller { } public static function l10n_form() { - $calls = I18n::instance()->getCallLog(); + $calls = I18n::instance()->call_log(); if ($calls) { $string_list = array(); @@ -92,7 +92,7 @@ class L10n_Client_Controller extends Controller { } $source = $message; $translation = ''; - if (I18n::instance()->hasTranslation($message, $options)) { + if (I18n::instance()->has_translation($message, $options)) { $translation = I18n::instance()->translate($message, $options); } $string_list[] = array('source' => $source, diff --git a/core/helpers/locale.php b/core/helpers/locale.php index 592f73b3..bd85cf6b 100644 --- a/core/helpers/locale.php +++ b/core/helpers/locale.php @@ -25,10 +25,10 @@ class locale_Core { /** * Return the list of available locales. */ - public static function available() { + static function available() { $locales = array(); - list ($supportedLanguages, $defaultCountry) = self::getLanguageData(); - foreach ($supportedLanguages as $language_tag => $country_locales) { + list ($supported_languages, $default_Country) = self::_get_language_data(); + foreach ($supported_languages as $language_tag => $country_locales) { foreach ($country_locales as $country_tag => $entry) { $locales[$language_tag . '_' . $country_tag] = $entry['description']; @@ -38,177 +38,176 @@ class locale_Core { return $locales; } - private static function getLanguageData() { - static $supportedLanguages = array(); - static $defaultCountry = array(); + private static function _get_language_data() { + static $supported_languages = array(); + static $default_country = array(); // TODO(andy_st): Might want to add a localizable language name as well. - if (empty($supportedLanguages)) { + if (empty($supported_languages)) { /* English */ - $supportedLanguages['en']['US']['description'] = 'English (US)'; - $supportedLanguages['en']['GB']['description'] = 'English (UK)'; - $defaultCountry['en'] = 'US'; + $supported_languages['en']['US']['description'] = 'English (US)'; + $supported_languages['en']['GB']['description'] = 'English (UK)'; + $default_country['en'] = 'US'; /* Afrikaans */ - $supportedLanguages['af']['ZA']['description'] = 'Afrikaans'; - $defaultCountry['af'] = 'ZA'; + $supported_languages['af']['ZA']['description'] = 'Afrikaans'; + $default_country['af'] = 'ZA'; /* Catalan */ - $supportedLanguages['ca']['ES']['description'] = 'Catalan'; - $defaultCountry['ca'] = 'ES'; + $supported_languages['ca']['ES']['description'] = 'Catalan'; + $default_country['ca'] = 'ES'; /* Czech */ - $supportedLanguages['cs']['CZ']['description'] = 'Česky'; - $defaultCountry['cs'] = 'CZ'; - + $supported_languages['cs']['CZ']['description'] = 'Česky'; + $default_country['cs'] = 'CZ'; + /* Danish */ - $supportedLanguages['da']['DK']['description'] = 'Dansk'; - $defaultCountry['da'] = 'DK'; - + $supported_languages['da']['DK']['description'] = 'Dansk'; + $default_country['da'] = 'DK'; + /* German */ - $supportedLanguages['de']['DE']['description'] = 'Deutsch'; - $defaultCountry['de'] = 'DE'; + $supported_languages['de']['DE']['description'] = 'Deutsch'; + $default_country['de'] = 'DE'; /* Spanish */ - $supportedLanguages['es']['ES']['description'] = 'Español'; - $supportedLanguages['es']['MX']['description'] = 'Español (MX)'; - $supportedLanguages['es']['AR']['description'] = 'Español (AR)'; - $defaultCountry['es'] = 'ES'; + $supported_languages['es']['ES']['description'] = 'Español'; + $supported_languages['es']['MX']['description'] = 'Español (MX)'; + $supported_languages['es']['AR']['description'] = 'Español (AR)'; + $default_country['es'] = 'ES'; /* Estonian */ - $supportedLanguages['et']['EE']['description'] = 'Eesti'; - $defaultCountry['et'] = 'EE'; + $supported_languages['et']['EE']['description'] = 'Eesti'; + $default_country['et'] = 'EE'; /* Basque */ - $supportedLanguages['eu']['ES']['description'] = 'Euskara'; - $defaultCountry['eu'] = 'ES'; + $supported_languages['eu']['ES']['description'] = 'Euskara'; + $default_country['eu'] = 'ES'; /* French */ - $supportedLanguages['fr']['FR']['description'] = 'Français'; - $defaultCountry['fr'] = 'FR'; - + $supported_languages['fr']['FR']['description'] = 'Français'; + $default_country['fr'] = 'FR'; + /* Irish */ - $supportedLanguages['ga']['IE']['description'] = 'Gaeilge'; - $defaultCountry['ga'] = 'IE'; - + $supported_languages['ga']['IE']['description'] = 'Gaeilge'; + $default_country['ga'] = 'IE'; + /* Greek */ - $supportedLanguages['el']['GR']['description'] = 'Greek'; - $defaultCountry['el'] = 'GR'; - - /* Icelandic */ - $supportedLanguages['is']['IS']['description'] = 'Icelandic'; - $defaultCountry['is'] = 'IS'; + $supported_languages['el']['GR']['description'] = 'Greek'; + $default_country['el'] = 'GR'; + /* Icelandic */ + $supported_languages['is']['IS']['description'] = 'Icelandic'; + $default_country['is'] = 'IS'; /* Italian */ - $supportedLanguages['it']['IT']['description'] = 'Italiano'; - $defaultCountry['it'] = 'IT'; + $supported_languages['it']['IT']['description'] = 'Italiano'; + $default_country['it'] = 'IT'; /* Latvian */ - $supportedLanguages['lv']['LV']['description'] = 'Latviešu'; - $defaultCountry['lv'] = 'LV'; + $supported_languages['lv']['LV']['description'] = 'Latviešu'; + $default_country['lv'] = 'LV'; /* Lithuanian */ - $supportedLanguages['lt']['LT']['description'] = 'Lietuvių'; - $defaultCountry['lt'] = 'LT'; + $supported_languages['lt']['LT']['description'] = 'Lietuvių'; + $default_country['lt'] = 'LT'; /* Hungarian */ - $supportedLanguages['hu']['HU']['description'] = 'Magyar'; - $defaultCountry['hu'] = 'HU'; + $supported_languages['hu']['HU']['description'] = 'Magyar'; + $default_country['hu'] = 'HU'; /* Dutch */ - $supportedLanguages['nl']['NL']['description'] = 'Nederlands'; - $defaultCountry['nl'] = 'NL'; + $supported_languages['nl']['NL']['description'] = 'Nederlands'; + $default_country['nl'] = 'NL'; /* Norwegian */ - $supportedLanguages['no']['NO']['description'] = 'Norsk bokmål'; - $defaultCountry['no'] = 'NO'; - + $supported_languages['no']['NO']['description'] = 'Norsk bokmål'; + $default_country['no'] = 'NO'; + /* Polish */ - $supportedLanguages['pl']['PL']['description'] = 'Polski'; - $defaultCountry['pl'] = 'PL'; - + $supported_languages['pl']['PL']['description'] = 'Polski'; + $default_country['pl'] = 'PL'; + /* Portuguese */ - $supportedLanguages['pt']['BR']['description'] = 'Português Brasileiro'; - $supportedLanguages['pt']['PT']['description'] = 'Português'; - $defaultCountry['pt'] = 'PT'; + $supported_languages['pt']['BR']['description'] = 'Português Brasileiro'; + $supported_languages['pt']['PT']['description'] = 'Português'; + $default_country['pt'] = 'PT'; /* Romanian */ - $supportedLanguages['ro']['RO']['description'] = 'Română'; - $defaultCountry['ro'] = 'RO'; + $supported_languages['ro']['RO']['description'] = 'Română'; + $default_country['ro'] = 'RO'; /* Slovak */ - $supportedLanguages['sk']['SK']['description'] = 'Slovenčina'; - $defaultCountry['sk'] = 'SK'; + $supported_languages['sk']['SK']['description'] = 'Slovenčina'; + $default_country['sk'] = 'SK'; /* Slovenian */ - $supportedLanguages['sl']['SI']['description'] = 'Slovenščina'; - $defaultCountry['sl'] = 'SI'; + $supported_languages['sl']['SI']['description'] = 'Slovenščina'; + $default_country['sl'] = 'SI'; /* Serbian */ - $supportedLanguages['sr']['CS']['description'] = 'Srpski'; - $defaultCountry['sr'] = 'CS'; + $supported_languages['sr']['CS']['description'] = 'Srpski'; + $default_country['sr'] = 'CS'; /* Finnish */ - $supportedLanguages['fi']['FI']['description'] = 'Suomi'; - $defaultCountry['fi'] = 'FI'; + $supported_languages['fi']['FI']['description'] = 'Suomi'; + $default_country['fi'] = 'FI'; /* Swedish */ - $supportedLanguages['sv']['SE']['description'] = 'Svenska'; - $defaultCountry['sv'] = 'SE'; + $supported_languages['sv']['SE']['description'] = 'Svenska'; + $default_country['sv'] = 'SE'; /* Ukrainian */ - $supportedLanguages['uk']['UA']['description'] = 'УкÑаÑнÑÑка'; - $defaultCountry['uk'] = 'UA'; - + $supported_languages['uk']['UA']['description'] = 'УкÑаÑнÑÑка'; + $default_country['uk'] = 'UA'; + /* Vietnamese */ - $supportedLanguages['vi']['VN']['description'] = 'Tiếng Việt'; - $defaultCountry['vi'] = 'VN'; + $supported_languages['vi']['VN']['description'] = 'Tiếng Việt'; + $default_country['vi'] = 'VN'; /* Turkish */ - $supportedLanguages['tr']['TR']['description'] = 'Türkçe'; - $defaultCountry['tr'] = 'TR'; + $supported_languages['tr']['TR']['description'] = 'Türkçe'; + $default_country['tr'] = 'TR'; /* Bulgarian */ - $supportedLanguages['bg']['BG']['description'] = + $supported_languages['bg']['BG']['description'] = 'Български'; - $defaultCountry['bg'] = 'BG'; + $default_country['bg'] = 'BG'; /* Russian */ - $supportedLanguages['ru']['RU']['description'] = + $supported_languages['ru']['RU']['description'] = 'Русский'; - $defaultCountry['ru'] = 'RU'; + $default_country['ru'] = 'RU'; /* Chinese */ - $supportedLanguages['zh']['CN']['description'] = '简体中文'; - $supportedLanguages['zh']['TW']['description'] = '繁體中文'; - $defaultCountry['zh'] = 'CN'; - + $supported_languages['zh']['CN']['description'] = '简体中文'; + $supported_languages['zh']['TW']['description'] = '繁體中文'; + $default_country['zh'] = 'CN'; + /* Korean */ - $supportedLanguages['ko']['KR']['description'] = '한국말'; - $defaultCountry['ko'] = 'KR'; + $supported_languages['ko']['KR']['description'] = '한국말'; + $default_country['ko'] = 'KR'; /* Japanese */ - $supportedLanguages['ja']['JP']['description'] = '日本語'; - $defaultCountry['ja'] = 'JP'; + $supported_languages['ja']['JP']['description'] = '日本語'; + $default_country['ja'] = 'JP'; /* Arabic */ - $supportedLanguages['ar']['SA']['description'] = + $supported_languages['ar']['SA']['description'] = 'العربية'; - $supportedLanguages['ar']['SA']['right-to-left'] = true; - $defaultCountry['ar'] = 'SA'; + $supported_languages['ar']['SA']['right-to-left'] = true; + $default_country['ar'] = 'SA'; /* Hebrew */ - $supportedLanguages['he']['IL']['description'] = 'עברית'; - $supportedLanguages['he']['IL']['right-to-left'] = true; - $defaultCountry['he'] = 'IL'; - + $supported_languages['he']['IL']['description'] = 'עברית'; + $supported_languages['he']['IL']['right-to-left'] = true; + $default_country['he'] = 'IL'; + /* Farsi */ - $supportedLanguages['fa']['IR']['description'] = 'فارسي'; - $supportedLanguages['fa']['IR']['right-to-left'] = true; - $defaultCountry['fa'] = 'IR'; + $supported_languages['fa']['IR']['description'] = 'فارسي'; + $supported_languages['fa']['IR']['right-to-left'] = true; + $default_country['fa'] = 'IR'; } - return array($supportedLanguages, $defaultCountry); + return array($supported_languages, $default_country); } -} +}
\ No newline at end of file diff --git a/core/libraries/I18n.php b/core/libraries/I18n.php index 475b14b6..a2d412f8 100644 --- a/core/libraries/I18n.php +++ b/core/libraries/I18n.php @@ -55,7 +55,7 @@ class I18n_Core { private function __construct($config) { $this->_config = $config; - $this->setLocale($config['default_locale']); + $this->locale($config['default_locale']); } public static function instance($config=null) { @@ -70,13 +70,16 @@ class I18n_Core { return self::$_instance; } - public function setLocale($locale) { - $this->_config['default_locale'] = $locale; - // Attempt to set PHP's locale as well (for number formatting, collation, etc.) - // TODO: See G2 for better fallack code. - $locale_prefs = array($locale); - $locale_prefs[] = 'en_US'; - setlocale(LC_ALL, $locale_prefs); + public function locale($locale=null) { + if ($locale) { + $this->_config['default_locale'] = $locale; + // Attempt to set PHP's locale as well (for number formatting, collation, etc.) + // TODO: See G2 for better fallack code. + $locale_prefs = array($locale); + $locale_prefs[] = 'en_US'; + setlocale(LC_ALL, $locale_prefs); + } + return $this->_config['default_locale']; } /** @@ -110,10 +113,6 @@ class I18n_Core { return $entry; } - public function getLocale() { - return $this->_config['default_locale']; - } - private function lookup($locale, $message) { if (!isset($this->_cache[$locale])) { $this->_cache[$locale] = array(); @@ -138,7 +137,7 @@ class I18n_Core { } } - $key = self::getMessageKey($message); + $key = self::get_message_key($message); if (isset($this->_cache[$locale][$key])) { return $this->_cache[$locale][$key]; @@ -147,7 +146,7 @@ class I18n_Core { } } - public function hasTranslation($message, $options=null) { + public function has_translation($message, $options=null) { $locale = empty($options['locale']) ? $this->_config['default_locale'] : $options['locale']; $count = empty($options['count']) ? null : $options['count']; $values = $options; @@ -168,7 +167,7 @@ class I18n_Core { } } - public static function getMessageKey($message) { + public static function get_message_key($message) { // If message is an array (plural forms), use the first form as message id. $key = is_array($message) ? array_shift($message) : $message; return md5($key, true); @@ -210,11 +209,11 @@ class I18n_Core { } private function log($message, $options) { - $key = self::getMessageKey($message); + $key = self::get_message_key($message); isset($this->_call_log[$key]) or $this->_call_log[$key] = array($message, $options); } - public function getCallLog() { + public function call_log() { return $this->_call_log; } diff --git a/core/tests/I18n_Test.php b/core/tests/I18n_Test.php index 65b5e79a..4a353538 100644 --- a/core/tests/I18n_Test.php +++ b/core/tests/I18n_Test.php @@ -43,7 +43,7 @@ class I18n_Test extends Unit_Test_Case { foreach ($messages_te_ST as $data) { list ($message, $translation) = $data; $entry = ORM::factory("incoming_translation"); - $entry->key = I18n::getMessageKey($message); + $entry->key = I18n::get_message_key($message); $entry->message = serialize($message); $entry->translation = serialize($translation); $entry->locale = 'te_ST'; |