Skip to content

Commit

Permalink
fixed #246
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Feb 9, 2020
1 parent 08c42eb commit b71edec
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Loader/MoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 11 additions & 3 deletions tests/MoLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -31,15 +32,14 @@ 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']);
$this->assertSame('', $headers['POT-Creation-Date']);
$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(
Expand All @@ -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());
Expand Down
13 changes: 12 additions & 1 deletion tests/PoLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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 [
Expand Down
Binary file modified tests/assets/translations.mo
Binary file not shown.
8 changes: 7 additions & 1 deletion tests/assets/translations.po
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@ msgid "Multibyte test"
msgstr "日本人は日本で話される言語です!"

msgid "Tabulation test"
msgstr "FIELD\tFIELD"
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."

0 comments on commit b71edec

Please sign in to comment.