diff --git a/src/Loader/MoLoader.php b/src/Loader/MoLoader.php index 22f92fb5..fe3e09a7 100644 --- a/src/Loader/MoLoader.php +++ b/src/Loader/MoLoader.php @@ -97,7 +97,7 @@ public function loadString(string $string, Translations $translations = null): T $v = explode("\x00", $translated); $translation->translate(array_shift($v)); - $translation->translatePlural($v); + $translation->translatePlural(...array_filter($v)); } return $translations; diff --git a/tests/MoLoaderTest.php b/tests/MoLoaderTest.php index 89580294..30a21a39 100644 --- a/tests/MoLoaderTest.php +++ b/tests/MoLoaderTest.php @@ -14,10 +14,11 @@ public function testMoLoader() $loader = new MoLoader(); $translations = $loader->loadFile(__DIR__.'/assets/translations.mo'); - $this->assertCount(10, $translations); + $this->assertCount(11, $translations); $array = $translations->getTranslations(); + $this->translation0(array_shift($array)); $this->translation1(array_shift($array)); $this->translation2(array_shift($array)); $this->translation3(array_shift($array)); @@ -31,7 +32,7 @@ public function testMoLoader() $headers = $translations->getHeaders()->toArray(); - $this->assertCount(13, $headers); + $this->assertCount(12, $headers); $this->assertSame('text/plain; charset=UTF-8', $headers['Content-Type']); $this->assertSame('8bit', $headers['Content-Transfer-Encoding']); @@ -39,7 +40,6 @@ public function testMoLoader() $this->assertSame('', $headers['PO-Revision-Date']); $this->assertSame('', $headers['Last-Translator']); $this->assertSame('', $headers['Language-Team']); - $this->assertSame('', $headers['Report-Msgid-Bugs-To']); $this->assertSame('1.0', $headers['MIME-Version']); $this->assertSame('bs', $headers['Language']); $this->assertSame( @@ -54,6 +54,14 @@ public function testMoLoader() $this->assertSame('bs', $translations->getLanguage()); } + private function translation0(Translation $translation) + { + $this->assertSame('%s has been added to your cart.', $translation->getOriginal()); + $this->assertSame('%s have been added to your cart.', $translation->getPlural()); + $this->assertSame('%s has been added to your cart.', $translation->getTranslation()); + $this->assertCount(1, $translation->getPluralTranslations()); + } + private function translation1(Translation $translation) { $this->assertSame('%ss must be unique for %ss %ss.', $translation->getOriginal()); diff --git a/tests/PoLoaderTest.php b/tests/PoLoaderTest.php index 42c0a5dd..1fc9d6af 100644 --- a/tests/PoLoaderTest.php +++ b/tests/PoLoaderTest.php @@ -14,7 +14,7 @@ public function testPoLoader() $loader = new PoLoader(); $translations = $loader->loadFile(__DIR__.'/assets/translations.po'); - $this->assertCount(13, $translations); + $this->assertCount(14, $translations); $array = $translations->getTranslations(); @@ -31,6 +31,7 @@ public function testPoLoader() $this->translation11(array_shift($array)); $this->translation12(array_shift($array)); $this->translation13(array_shift($array)); + $this->translation14(array_shift($array)); $headers = $translations->getHeaders()->toArray(); @@ -206,6 +207,16 @@ private function translation13(Translation $translation) $this->assertCount(0, $translation->getReferences()); } + private function translation14(Translation $translation) + { + $this->assertSame('%s has been added to your cart.', $translation->getOriginal()); + $this->assertSame('%s have been added to your cart.', $translation->getPlural()); + $this->assertSame('%s has been added to your cart.', $translation->getTranslation()); + $this->assertSame(['%s have been added to your cart.'], $translation->getPluralTranslations()); + $this->assertCount(1, $translation->getComments()); + $this->assertCount(0, $translation->getReferences()); + } + public function stringDecodeProvider() { return [ diff --git a/tests/assets/translations.mo b/tests/assets/translations.mo index 9baefcf0..095ffa3b 100644 Binary files a/tests/assets/translations.mo and b/tests/assets/translations.mo differ diff --git a/tests/assets/translations.po b/tests/assets/translations.po index 2936098b..219441f7 100644 --- a/tests/assets/translations.po +++ b/tests/assets/translations.po @@ -77,4 +77,10 @@ msgid "Multibyte test" msgstr "日本人は日本で話される言語です!" msgid "Tabulation test" -msgstr "FIELD\tFIELD" \ No newline at end of file +msgstr "FIELD\tFIELD" + +# Issue https://github.com/php-gettext/Gettext/issues/246 +msgid "%s has been added to your cart." +msgid_plural "%s have been added to your cart." +msgstr[0] "%s has been added to your cart." +msgstr[1] "%s have been added to your cart." \ No newline at end of file