diff --git a/src/Translator/Translator.php b/src/Translator/Translator.php index 1d6e0441..727c61ba 100644 --- a/src/Translator/Translator.php +++ b/src/Translator/Translator.php @@ -401,6 +401,8 @@ public function translatePlural( } return ($number == 1 ? $singular : $plural); + } elseif (is_string($translation)) { + $translation = array($translation); } $index = $this->messages[$textDomain][$locale] diff --git a/test/Translator/TranslatorTest.php b/test/Translator/TranslatorTest.php index 43d79d22..dbf90b12 100644 --- a/test/Translator/TranslatorTest.php +++ b/test/Translator/TranslatorTest.php @@ -219,6 +219,26 @@ public function testTranslatePlurals() $this->assertEquals('Message 5 (en) Plural 1', $pl1); $this->assertEquals('Message 5 (en) Plural 2', $pl2); } + + public function testTranslateNoPlurals() + { + // Some languages such as Japanese and Chinese does not have plural forms + $this->translator->setLocale('ja_JP'); + $this->translator->addTranslationFile( + 'phparray', + $this->testFilesDir . '/testarray/translation-noplural-ja_JP.php', + 'default', + 'ja_JP' + ); + + $pl0 = $this->translator->translatePlural('Message 9', 'Message 9 Plural', 1); + $pl1 = $this->translator->translatePlural('Message 9', 'Message 9 Plural', 2); + $pl2 = $this->translator->translatePlural('Message 9', 'Message 9 Plural', 10); + + $this->assertEquals('Message 9 (ja)', $pl0); + $this->assertEquals('Message 9 (ja)', $pl1); + $this->assertEquals('Message 9 (ja)', $pl2); + } public function testTranslateNonExistantLocale() { diff --git a/test/Translator/_files/testarray/translation-noplural-ja_JP.php b/test/Translator/_files/testarray/translation-noplural-ja_JP.php new file mode 100644 index 00000000..5f48b86b --- /dev/null +++ b/test/Translator/_files/testarray/translation-noplural-ja_JP.php @@ -0,0 +1,15 @@ + array( + 'plural_forms' => 'nplurals=1; plural=0;' + ), + 'Message 9' => 'Message 9 (ja)', +);