From 3ed7a5af46586f186a4627d8b029aec7c3ff579d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 24 Nov 2009 19:24:02 -0800 Subject: Rename I18n to Gallery_I18n to avoid conflict with Kohana 2.4 --- modules/gallery/controllers/l10n_client.php | 8 +- modules/gallery/helpers/l10n_scanner.php | 2 +- modules/gallery/helpers/locales.php | 6 +- modules/gallery/hooks/init_gallery.php | 2 +- modules/gallery/libraries/Gallery_I18n.php | 430 ++++++++++++++++++++++++++++ modules/gallery/libraries/I18n.php | 430 ---------------------------- modules/gallery/tests/I18n_Test.php | 6 +- 7 files changed, 442 insertions(+), 442 deletions(-) create mode 100644 modules/gallery/libraries/Gallery_I18n.php delete mode 100644 modules/gallery/libraries/I18n.php (limited to 'modules') diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php index 6db67d3b..3801e6aa 100644 --- a/modules/gallery/controllers/l10n_client.php +++ b/modules/gallery/controllers/l10n_client.php @@ -24,7 +24,7 @@ class L10n_Client_Controller extends Controller { access::forbidden(); } - $locale = I18n::instance()->locale(); + $locale = Gallery_I18n::instance()->locale(); $input = Input::instance(); $key = $input->post("l10n-message-key"); @@ -36,7 +36,7 @@ class L10n_Client_Controller extends Controller { if (!$root_message->loaded) { throw new Exception("@todo bad request data / illegal state"); } - $is_plural = I18n::is_plural_message(unserialize($root_message->message)); + $is_plural = Gallery_I18n::is_plural_message(unserialize($root_message->message)); if ($is_plural) { $plural_forms = l10n_client::plural_forms($locale); @@ -122,9 +122,9 @@ class L10n_Client_Controller extends Controller { $calls[$row->key] = array(unserialize($row->message), array()); } } else { - $calls = I18n::instance()->call_log(); + $calls = Gallery_I18n::instance()->call_log(); } - $locale = I18n::instance()->locale(); + $locale = Gallery_I18n::instance()->locale(); if ($calls) { $translations = array(); diff --git a/modules/gallery/helpers/l10n_scanner.php b/modules/gallery/helpers/l10n_scanner.php index a8059b3a..e36d419d 100644 --- a/modules/gallery/helpers/l10n_scanner.php +++ b/modules/gallery/helpers/l10n_scanner.php @@ -37,7 +37,7 @@ class l10n_scanner_Core { } } - $key = I18n::get_message_key($message); + $key = Gallery_I18n::get_message_key($message); if (array_key_exists($key, $cache)) { return $cache[$key]; } diff --git a/modules/gallery/helpers/locales.php b/modules/gallery/helpers/locales.php index 2de029ff..8d76e333 100644 --- a/modules/gallery/helpers/locales.php +++ b/modules/gallery/helpers/locales.php @@ -125,13 +125,13 @@ class locales_Core { if (empty(self::$locales)) { self::_init_language_data(); } - $locale or $locale = I18n::instance()->locale(); + $locale or $locale = Gallery_I18n::instance()->locale(); return self::$locales["$locale"]; } static function is_rtl($locale=null) { - $locale or $locale = I18n::instance()->locale(); + $locale or $locale = Gallery_I18n::instance()->locale(); list ($language, $territory) = explode('_', $locale . "_"); return in_array($language, array("he", "fa", "ar")); } @@ -233,7 +233,7 @@ class locales_Core { } // If we have any preference, override the site's default locale if ($locale) { - I18n::instance()->locale($locale); + Gallery_I18n::instance()->locale($locale); } } diff --git a/modules/gallery/hooks/init_gallery.php b/modules/gallery/hooks/init_gallery.php index b2d9c4de..4ce9bab4 100644 --- a/modules/gallery/hooks/init_gallery.php +++ b/modules/gallery/hooks/init_gallery.php @@ -24,7 +24,7 @@ if (!file_exists(VARPATH . "database.php")) { url::redirect(url::abs_file("installer")); } -Event::add("system.ready", array("I18n", "instance")); +Event::add("system.ready", array("Gallery_I18n", "instance")); Event::add("system.ready", array("module", "load_modules")); Event::add("system.ready", array("gallery", "ready")); Event::add("system.post_routing", array("url", "parse_url")); diff --git a/modules/gallery/libraries/Gallery_I18n.php b/modules/gallery/libraries/Gallery_I18n.php new file mode 100644 index 00000000..0571fe58 --- /dev/null +++ b/modules/gallery/libraries/Gallery_I18n.php @@ -0,0 +1,430 @@ +translate($message, $options); +} + +/** + * Translates a localizable message with plural forms. + * @param $singular String The message to be translated. E.g. "There is one album." + * @param $plural String The plural message to be translated. E.g. + * "There are %count albums." + * @param $count Number The number which is inserted for the %count placeholder and + * which is used to select the proper plural form ($singular or $plural). + * @param $options array (optional) Options array for key value pairs which are used + * for pluralization and interpolation. Special key: "locale" to override the + * currently configured locale. + * @return String The translated message string. + */ +function t2($singular, $plural, $count, $options=array()) { + return Gallery_I18n::instance()->translate(array("one" => $singular, "other" => $plural), + array_merge($options, array("count" => $count))); +} + +class Gallery_I18n_Core { + private static $_instance; + private $_config = array(); + private $_call_log = array(); + private $_cache = array(); + + private function __construct($config) { + $this->_config = $config; + $this->locale($config['default_locale']); + } + + public static function instance($config=null) { + if (self::$_instance == NULL || isset($config)) { + $config = isset($config) ? $config : Kohana::config('locale'); + if (empty($config['default_locale'])) { + $config['default_locale'] = module::get_var('gallery', 'default_locale'); + } + self::$_instance = new Gallery_I18n_Core($config); + } + + return self::$_instance; + } + + 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'; + $new_locale = setlocale(LC_ALL, $locale_prefs); + if (is_string($new_locale) && strpos($new_locale, 'tr') === 0) { + // Make PHP 5 work with Turkish (the localization results are mixed though). + // Hack for http://bugs.php.net/18556 + setlocale(LC_CTYPE, 'C'); + } + } + return $this->_config['default_locale']; + } + + /** + * Translates a localizable message. + * + * Security: + * The returned string is safe for use in HTML (it contains a safe subset of HTML and + * interpolation parameters are converted to HTML entities). + * For use in JavaScript, please call ->for_js() on it. + * + * @param $message String|array The message to be translated. E.g. "Hello world" + * or array("one" => "One album", "other" => "%count albums") + * @param $options array (optional) Options array for key value pairs which are used + * for pluralization and interpolation. Special keys are "count" and "locale", + * the latter to override the currently configured locale. + * @return String The translated message string. + */ + public function translate($message, $options=array()) { + $locale = empty($options['locale']) ? $this->_config['default_locale'] : $options['locale']; + $count = isset($options['count']) ? $options['count'] : null; + $values = $options; + unset($values['locale']); + $this->log($message, $options); + + $entry = $this->lookup($locale, $message); + + if (null === $entry) { + // Default to the root locale. + $entry = $message; + $locale = $this->_config['root_locale']; + } + + $entry = $this->pluralize($locale, $entry, $count); + + $entry = $this->interpolate($locale, $entry, $values); + + return SafeString::of_safe_html($entry); + } + + private function lookup($locale, $message) { + if (!isset($this->_cache[$locale])) { + $this->_cache[$locale] = array(); + // TODO: Load data from locale file instead of the DB. + foreach (Database::instance() + ->select("key", "translation") + ->from("incoming_translations") + ->where(array("locale" => $locale)) + ->get() + ->as_array() as $row) { + $this->_cache[$locale][$row->key] = unserialize($row->translation); + } + + // Override incoming with outgoing... + foreach (Database::instance() + ->select("key", "translation") + ->from("outgoing_translations") + ->where(array("locale" => $locale)) + ->get() + ->as_array() as $row) { + $this->_cache[$locale][$row->key] = unserialize($row->translation); + } + } + + $key = self::get_message_key($message); + + if (isset($this->_cache[$locale][$key])) { + return $this->_cache[$locale][$key]; + } else { + return null; + } + } + + public function has_translation($message, $options=null) { + $locale = empty($options['locale']) ? $this->_config['default_locale'] : $options['locale']; + + $entry = $this->lookup($locale, $message); + + if (null === $entry) { + return false; + } else if (!is_array($message)) { + return $entry !== ''; + } else { + if (!is_array($entry) || empty($entry)) { + return false; + } + // It would be better to verify that all the locale's plural forms have a non-empty + // translation, but this is fine for now. + foreach ($entry as $value) { + if ($value === '') { + return false; + } + } + return true; + } + } + + static function get_message_key($message) { + $as_string = is_array($message) ? implode('|', $message) : $message; + return md5($as_string); + } + + static function is_plural_message($message) { + return is_array($message); + } + + private function interpolate($locale, $string, $key_values) { + // TODO: Handle locale specific number formatting. + + // Replace x_y before replacing x. + krsort($key_values, SORT_STRING); + + $keys = array(); + $values = array(); + foreach ($key_values as $key => $value) { + $keys[] = "%$key"; + $values[] = new SafeString($value); + } + return str_replace($keys, $values, $string); + } + + private function pluralize($locale, $entry, $count) { + if (!is_array($entry)) { + return $entry; + } + + $plural_key = self::get_plural_key($locale, $count); + if (!isset($entry[$plural_key])) { + // Fallback to the default plural form. + $plural_key = 'other'; + } + + if (isset($entry[$plural_key])) { + return $entry[$plural_key]; + } else { + // Fallback to just any plural form. + list ($plural_key, $string) = each($entry); + return $string; + } + } + + private function log($message, $options) { + $key = self::get_message_key($message); + isset($this->_call_log[$key]) or $this->_call_log[$key] = array($message, $options); + } + + public function call_log() { + return $this->_call_log; + } + + private static function get_plural_key($locale, $count) { + $parts = explode('_', $locale); + $language = $parts[0]; + + // Data from CLDR 1.6 (http://unicode.org/cldr/data/common/supplemental/plurals.xml). + // Docs: http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html + switch ($language) { + case 'az': + case 'fa': + case 'hu': + case 'ja': + case 'ko': + case 'my': + case 'to': + case 'tr': + case 'vi': + case 'yo': + case 'zh': + case 'bo': + case 'dz': + case 'id': + case 'jv': + case 'ka': + case 'km': + case 'kn': + case 'ms': + case 'th': + return 'other'; + + case 'ar': + if ($count == 0) { + return 'zero'; + } else if ($count == 1) { + return 'one'; + } else if ($count == 2) { + return 'two'; + } else if (is_int($count) && ($i = $count % 100) >= 3 && $i <= 10) { + return 'few'; + } else if (is_int($count) && ($i = $count % 100) >= 11 && $i <= 99) { + return 'many'; + } else { + return 'other'; + } + + case 'pt': + case 'am': + case 'bh': + case 'fil': + case 'tl': + case 'guw': + case 'hi': + case 'ln': + case 'mg': + case 'nso': + case 'ti': + case 'wa': + if ($count == 0 || $count == 1) { + return 'one'; + } else { + return 'other'; + } + + case 'fr': + if ($count >= 0 and $count < 2) { + return 'one'; + } else { + return 'other'; + } + + case 'lv': + if ($count == 0) { + return 'zero'; + } else if ($count % 10 == 1 && $count % 100 != 11) { + return 'one'; + } else { + return 'other'; + } + + case 'ga': + case 'se': + case 'sma': + case 'smi': + case 'smj': + case 'smn': + case 'sms': + if ($count == 1) { + return 'one'; + } else if ($count == 2) { + return 'two'; + } else { + return 'other'; + } + + case 'ro': + case 'mo': + if ($count == 1) { + return 'one'; + } else if (is_int($count) && $count == 0 && ($i = $count % 100) >= 1 && $i <= 19) { + return 'few'; + } else { + return 'other'; + } + + case 'lt': + if (is_int($count) && $count % 10 == 1 && $count % 100 != 11) { + return 'one'; + } else if (is_int($count) && ($i = $count % 10) >= 2 && $i <= 9 && ($i = $count % 100) < 11 && $i > 19) { + return 'few'; + } else { + return 'other'; + } + + case 'hr': + case 'ru': + case 'sr': + case 'uk': + case 'be': + case 'bs': + case 'sh': + if (is_int($count) && $count % 10 == 1 && $count % 100 != 11) { + return 'one'; + } else if (is_int($count) && ($i = $count % 10) >= 2 && $i <= 4 && ($i = $count % 100) < 12 && $i > 14) { + return 'few'; + } else if (is_int($count) && ($count % 10 == 0 || (($i = $count % 10) >= 5 && $i <= 9) || (($i = $count % 100) >= 11 && $i <= 14))) { + return 'many'; + } else { + return 'other'; + } + + case 'cs': + case 'sk': + if ($count == 1) { + return 'one'; + } else if (is_int($count) && $count >= 2 && $count <= 4) { + return 'few'; + } else { + return 'other'; + } + + case 'pl': + if ($count == 1) { + return 'one'; + } else if (is_int($count) && ($i = $count % 10) >= 2 && $i <= 4 && + ($i = $count % 100) < 12 && $i > 14 && ($i = $count % 100) < 22 && $i > 24) { + return 'few'; + } else { + return 'other'; + } + + case 'sl': + if ($count % 100 == 1) { + return 'one'; + } else if ($count % 100 == 2) { + return 'two'; + } else if (is_int($count) && ($i = $count % 100) >= 3 && $i <= 4) { + return 'few'; + } else { + return 'other'; + } + + case 'mt': + if ($count == 1) { + return 'one'; + } else if ($count == 0 || is_int($count) && ($i = $count % 100) >= 2 && $i <= 10) { + return 'few'; + } else if (is_int($count) && ($i = $count % 100) >= 11 && $i <= 19) { + return 'many'; + } else { + return 'other'; + } + + case 'mk': + if ($count % 10 == 1) { + return 'one'; + } else { + return 'other'; + } + + case 'cy': + if ($count == 1) { + return 'one'; + } else if ($count == 2) { + return 'two'; + } else if ($count == 8 || $count == 11) { + return 'many'; + } else { + return 'other'; + } + + default: // en, de, etc. + return $count == 1 ? 'one' : 'other'; + } + } +} diff --git a/modules/gallery/libraries/I18n.php b/modules/gallery/libraries/I18n.php deleted file mode 100644 index c3336052..00000000 --- a/modules/gallery/libraries/I18n.php +++ /dev/null @@ -1,430 +0,0 @@ -translate($message, $options); -} - -/** - * Translates a localizable message with plural forms. - * @param $singular String The message to be translated. E.g. "There is one album." - * @param $plural String The plural message to be translated. E.g. - * "There are %count albums." - * @param $count Number The number which is inserted for the %count placeholder and - * which is used to select the proper plural form ($singular or $plural). - * @param $options array (optional) Options array for key value pairs which are used - * for pluralization and interpolation. Special key: "locale" to override the - * currently configured locale. - * @return String The translated message string. - */ -function t2($singular, $plural, $count, $options=array()) { - return I18n::instance()->translate(array("one" => $singular, "other" => $plural), - array_merge($options, array("count" => $count))); -} - -class I18n_Core { - private static $_instance; - private $_config = array(); - private $_call_log = array(); - private $_cache = array(); - - private function __construct($config) { - $this->_config = $config; - $this->locale($config['default_locale']); - } - - public static function instance($config=null) { - if (self::$_instance == NULL || isset($config)) { - $config = isset($config) ? $config : Kohana::config('locale'); - if (empty($config['default_locale'])) { - $config['default_locale'] = module::get_var('gallery', 'default_locale'); - } - self::$_instance = new I18n_Core($config); - } - - return self::$_instance; - } - - 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'; - $new_locale = setlocale(LC_ALL, $locale_prefs); - if (is_string($new_locale) && strpos($new_locale, 'tr') === 0) { - // Make PHP 5 work with Turkish (the localization results are mixed though). - // Hack for http://bugs.php.net/18556 - setlocale(LC_CTYPE, 'C'); - } - } - return $this->_config['default_locale']; - } - - /** - * Translates a localizable message. - * - * Security: - * The returned string is safe for use in HTML (it contains a safe subset of HTML and - * interpolation parameters are converted to HTML entities). - * For use in JavaScript, please call ->for_js() on it. - * - * @param $message String|array The message to be translated. E.g. "Hello world" - * or array("one" => "One album", "other" => "%count albums") - * @param $options array (optional) Options array for key value pairs which are used - * for pluralization and interpolation. Special keys are "count" and "locale", - * the latter to override the currently configured locale. - * @return String The translated message string. - */ - public function translate($message, $options=array()) { - $locale = empty($options['locale']) ? $this->_config['default_locale'] : $options['locale']; - $count = isset($options['count']) ? $options['count'] : null; - $values = $options; - unset($values['locale']); - $this->log($message, $options); - - $entry = $this->lookup($locale, $message); - - if (null === $entry) { - // Default to the root locale. - $entry = $message; - $locale = $this->_config['root_locale']; - } - - $entry = $this->pluralize($locale, $entry, $count); - - $entry = $this->interpolate($locale, $entry, $values); - - return SafeString::of_safe_html($entry); - } - - private function lookup($locale, $message) { - if (!isset($this->_cache[$locale])) { - $this->_cache[$locale] = array(); - // TODO: Load data from locale file instead of the DB. - foreach (Database::instance() - ->select("key", "translation") - ->from("incoming_translations") - ->where(array("locale" => $locale)) - ->get() - ->as_array() as $row) { - $this->_cache[$locale][$row->key] = unserialize($row->translation); - } - - // Override incoming with outgoing... - foreach (Database::instance() - ->select("key", "translation") - ->from("outgoing_translations") - ->where(array("locale" => $locale)) - ->get() - ->as_array() as $row) { - $this->_cache[$locale][$row->key] = unserialize($row->translation); - } - } - - $key = self::get_message_key($message); - - if (isset($this->_cache[$locale][$key])) { - return $this->_cache[$locale][$key]; - } else { - return null; - } - } - - public function has_translation($message, $options=null) { - $locale = empty($options['locale']) ? $this->_config['default_locale'] : $options['locale']; - - $entry = $this->lookup($locale, $message); - - if (null === $entry) { - return false; - } else if (!is_array($message)) { - return $entry !== ''; - } else { - if (!is_array($entry) || empty($entry)) { - return false; - } - // It would be better to verify that all the locale's plural forms have a non-empty - // translation, but this is fine for now. - foreach ($entry as $value) { - if ($value === '') { - return false; - } - } - return true; - } - } - - static function get_message_key($message) { - $as_string = is_array($message) ? implode('|', $message) : $message; - return md5($as_string); - } - - static function is_plural_message($message) { - return is_array($message); - } - - private function interpolate($locale, $string, $key_values) { - // TODO: Handle locale specific number formatting. - - // Replace x_y before replacing x. - krsort($key_values, SORT_STRING); - - $keys = array(); - $values = array(); - foreach ($key_values as $key => $value) { - $keys[] = "%$key"; - $values[] = new SafeString($value); - } - return str_replace($keys, $values, $string); - } - - private function pluralize($locale, $entry, $count) { - if (!is_array($entry)) { - return $entry; - } - - $plural_key = self::get_plural_key($locale, $count); - if (!isset($entry[$plural_key])) { - // Fallback to the default plural form. - $plural_key = 'other'; - } - - if (isset($entry[$plural_key])) { - return $entry[$plural_key]; - } else { - // Fallback to just any plural form. - list ($plural_key, $string) = each($entry); - return $string; - } - } - - private function log($message, $options) { - $key = self::get_message_key($message); - isset($this->_call_log[$key]) or $this->_call_log[$key] = array($message, $options); - } - - public function call_log() { - return $this->_call_log; - } - - private static function get_plural_key($locale, $count) { - $parts = explode('_', $locale); - $language = $parts[0]; - - // Data from CLDR 1.6 (http://unicode.org/cldr/data/common/supplemental/plurals.xml). - // Docs: http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html - switch ($language) { - case 'az': - case 'fa': - case 'hu': - case 'ja': - case 'ko': - case 'my': - case 'to': - case 'tr': - case 'vi': - case 'yo': - case 'zh': - case 'bo': - case 'dz': - case 'id': - case 'jv': - case 'ka': - case 'km': - case 'kn': - case 'ms': - case 'th': - return 'other'; - - case 'ar': - if ($count == 0) { - return 'zero'; - } else if ($count == 1) { - return 'one'; - } else if ($count == 2) { - return 'two'; - } else if (is_int($count) && ($i = $count % 100) >= 3 && $i <= 10) { - return 'few'; - } else if (is_int($count) && ($i = $count % 100) >= 11 && $i <= 99) { - return 'many'; - } else { - return 'other'; - } - - case 'pt': - case 'am': - case 'bh': - case 'fil': - case 'tl': - case 'guw': - case 'hi': - case 'ln': - case 'mg': - case 'nso': - case 'ti': - case 'wa': - if ($count == 0 || $count == 1) { - return 'one'; - } else { - return 'other'; - } - - case 'fr': - if ($count >= 0 and $count < 2) { - return 'one'; - } else { - return 'other'; - } - - case 'lv': - if ($count == 0) { - return 'zero'; - } else if ($count % 10 == 1 && $count % 100 != 11) { - return 'one'; - } else { - return 'other'; - } - - case 'ga': - case 'se': - case 'sma': - case 'smi': - case 'smj': - case 'smn': - case 'sms': - if ($count == 1) { - return 'one'; - } else if ($count == 2) { - return 'two'; - } else { - return 'other'; - } - - case 'ro': - case 'mo': - if ($count == 1) { - return 'one'; - } else if (is_int($count) && $count == 0 && ($i = $count % 100) >= 1 && $i <= 19) { - return 'few'; - } else { - return 'other'; - } - - case 'lt': - if (is_int($count) && $count % 10 == 1 && $count % 100 != 11) { - return 'one'; - } else if (is_int($count) && ($i = $count % 10) >= 2 && $i <= 9 && ($i = $count % 100) < 11 && $i > 19) { - return 'few'; - } else { - return 'other'; - } - - case 'hr': - case 'ru': - case 'sr': - case 'uk': - case 'be': - case 'bs': - case 'sh': - if (is_int($count) && $count % 10 == 1 && $count % 100 != 11) { - return 'one'; - } else if (is_int($count) && ($i = $count % 10) >= 2 && $i <= 4 && ($i = $count % 100) < 12 && $i > 14) { - return 'few'; - } else if (is_int($count) && ($count % 10 == 0 || (($i = $count % 10) >= 5 && $i <= 9) || (($i = $count % 100) >= 11 && $i <= 14))) { - return 'many'; - } else { - return 'other'; - } - - case 'cs': - case 'sk': - if ($count == 1) { - return 'one'; - } else if (is_int($count) && $count >= 2 && $count <= 4) { - return 'few'; - } else { - return 'other'; - } - - case 'pl': - if ($count == 1) { - return 'one'; - } else if (is_int($count) && ($i = $count % 10) >= 2 && $i <= 4 && - ($i = $count % 100) < 12 && $i > 14 && ($i = $count % 100) < 22 && $i > 24) { - return 'few'; - } else { - return 'other'; - } - - case 'sl': - if ($count % 100 == 1) { - return 'one'; - } else if ($count % 100 == 2) { - return 'two'; - } else if (is_int($count) && ($i = $count % 100) >= 3 && $i <= 4) { - return 'few'; - } else { - return 'other'; - } - - case 'mt': - if ($count == 1) { - return 'one'; - } else if ($count == 0 || is_int($count) && ($i = $count % 100) >= 2 && $i <= 10) { - return 'few'; - } else if (is_int($count) && ($i = $count % 100) >= 11 && $i <= 19) { - return 'many'; - } else { - return 'other'; - } - - case 'mk': - if ($count % 10 == 1) { - return 'one'; - } else { - return 'other'; - } - - case 'cy': - if ($count == 1) { - return 'one'; - } else if ($count == 2) { - return 'two'; - } else if ($count == 8 || $count == 11) { - return 'many'; - } else { - return 'other'; - } - - default: // en, de, etc. - return $count == 1 ? 'one' : 'other'; - } - } -} diff --git a/modules/gallery/tests/I18n_Test.php b/modules/gallery/tests/I18n_Test.php index 9010606a..d0555cbf 100644 --- a/modules/gallery/tests/I18n_Test.php +++ b/modules/gallery/tests/I18n_Test.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class I18n_Test extends Unit_Test_Case { +class Gallery_I18n_Test extends Unit_Test_Case { private $i18n; public function setup() { @@ -26,7 +26,7 @@ class I18n_Test extends Unit_Test_Case { 'root_locale' => 'en', 'default_locale' => 'te_ST', 'locale_dir' => VARPATH . 'locale/'); - $this->i18n = I18n::instance($config); + $this->i18n = Gallery_I18n::instance($config); ORM::factory("incoming_translation") ->where("locale", "te_ST") @@ -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::get_message_key($message); + $entry->key = Gallery_I18n::get_message_key($message); $entry->message = serialize($message); $entry->translation = serialize($translation); $entry->locale = 'te_ST'; -- cgit v1.2.3