diff options
author | Andy Staudacher <andy.st@gmail.com> | 2009-03-18 02:40:16 +0000 |
---|---|---|
committer | Andy Staudacher <andy.st@gmail.com> | 2009-03-18 02:40:16 +0000 |
commit | 4971db37d48ed184f8f66a3b2ed3cf89235a660b (patch) | |
tree | 65027c77f10191035b6410db75c5863bc9d5a534 | |
parent | f8d49e8a097e865158a73b3c8ef94bb05f7cb626 (diff) |
Fix for ticket 142: Choose plural form "other" for count == 0 (unless the locale has a specific plural form for zero)
-rw-r--r-- | core/libraries/I18n.php | 4 | ||||
-rw-r--r-- | core/tests/I18n_Test.php | 9 |
2 files changed, 10 insertions, 3 deletions
diff --git a/core/libraries/I18n.php b/core/libraries/I18n.php index 7bb2eff6..7c1bafd9 100644 --- a/core/libraries/I18n.php +++ b/core/libraries/I18n.php @@ -93,7 +93,7 @@ class I18n_Core { */ public function translate($message, $options=array()) { $locale = empty($options['locale']) ? $this->_config['default_locale'] : $options['locale']; - $count = empty($options['count']) ? null : $options['count']; + $count = isset($options['count']) ? $options['count'] : null; $values = $options; unset($values['locale']); $this->log($message, $options); @@ -188,8 +188,6 @@ class I18n_Core { private function pluralize($locale, $entry, $count) { if (!is_array($entry)) { return $entry; - } else if ($count == null) { - $count = $locale == "en" ? 0 : 1; } $plural_key = self::get_plural_key($locale, $count); diff --git a/core/tests/I18n_Test.php b/core/tests/I18n_Test.php index f0ed827d..3a5e24f4 100644 --- a/core/tests/I18n_Test.php +++ b/core/tests/I18n_Test.php @@ -96,4 +96,13 @@ class I18n_Test extends Unit_Test_Case { $result = $this->i18n->translate('Hello %name, how are you today?', array('foo' => 'bar')); $this->assert_equal('Hallo %name, wie geht es Dir heute?', $result); } + + public function translate_plural_zero_test() { + // te_ST has the same plural rules as en and de. + // For count 0, plural form "other" should be used. + $result = $this->i18n->translate(array('one' => 'One item has been added', + 'other' => '%count elements have been added'), + array('count' => 0)); + $this->assert_equal('0 Elemente wurden hinzugefuegt.', $result); + } }
\ No newline at end of file |