From 1cfed1fac1f2aa109e96c2aa5c9f66002610b0f8 Mon Sep 17 00:00:00 2001 From: Andy Staudacher Date: Tue, 2 Jun 2009 00:43:04 -0700 Subject: Extend L10n client to provide UI for plural translation. Ticket 148. --- modules/gallery/libraries/I18n.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'modules/gallery/libraries') diff --git a/modules/gallery/libraries/I18n.php b/modules/gallery/libraries/I18n.php index f2801169..03a6d8f6 100644 --- a/modules/gallery/libraries/I18n.php +++ b/modules/gallery/libraries/I18n.php @@ -148,30 +148,37 @@ class I18n_Core { 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; - unset($values['locale']); - $this->log($message, $options); $entry = $this->lookup($locale, $message); if (null === $entry) { return false; - } else if (!is_array($entry)) { + } else if (!is_array($message)) { return $entry !== ''; } else { - $plural_key = self::get_plural_key($locale, $count); - return isset($entry[$plural_key]) - && $entry[$plural_key] !== null - && $entry[$plural_key] !== ''; + 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; } } - public static function get_message_key($message) { + 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, $values) { // TODO: Handle locale specific number formatting. -- cgit v1.2.3