Skip to content

Commit b71edec

Browse files
committed
fixed #246
1 parent 08c42eb commit b71edec

5 files changed

Lines changed: 31 additions & 6 deletions

File tree

src/Loader/MoLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function loadString(string $string, Translations $translations = null): T
9797

9898
$v = explode("\x00", $translated);
9999
$translation->translate(array_shift($v));
100-
$translation->translatePlural($v);
100+
$translation->translatePlural(...array_filter($v));
101101
}
102102

103103
return $translations;

tests/MoLoaderTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ public function testMoLoader()
1414
$loader = new MoLoader();
1515
$translations = $loader->loadFile(__DIR__.'/assets/translations.mo');
1616

17-
$this->assertCount(10, $translations);
17+
$this->assertCount(11, $translations);
1818

1919
$array = $translations->getTranslations();
2020

21+
$this->translation0(array_shift($array));
2122
$this->translation1(array_shift($array));
2223
$this->translation2(array_shift($array));
2324
$this->translation3(array_shift($array));
@@ -31,15 +32,14 @@ public function testMoLoader()
3132

3233
$headers = $translations->getHeaders()->toArray();
3334

34-
$this->assertCount(13, $headers);
35+
$this->assertCount(12, $headers);
3536

3637
$this->assertSame('text/plain; charset=UTF-8', $headers['Content-Type']);
3738
$this->assertSame('8bit', $headers['Content-Transfer-Encoding']);
3839
$this->assertSame('', $headers['POT-Creation-Date']);
3940
$this->assertSame('', $headers['PO-Revision-Date']);
4041
$this->assertSame('', $headers['Last-Translator']);
4142
$this->assertSame('', $headers['Language-Team']);
42-
$this->assertSame('', $headers['Report-Msgid-Bugs-To']);
4343
$this->assertSame('1.0', $headers['MIME-Version']);
4444
$this->assertSame('bs', $headers['Language']);
4545
$this->assertSame(
@@ -54,6 +54,14 @@ public function testMoLoader()
5454
$this->assertSame('bs', $translations->getLanguage());
5555
}
5656

57+
private function translation0(Translation $translation)
58+
{
59+
$this->assertSame('%s has been added to your cart.', $translation->getOriginal());
60+
$this->assertSame('%s have been added to your cart.', $translation->getPlural());
61+
$this->assertSame('%s has been added to your cart.', $translation->getTranslation());
62+
$this->assertCount(1, $translation->getPluralTranslations());
63+
}
64+
5765
private function translation1(Translation $translation)
5866
{
5967
$this->assertSame('%ss must be unique for %ss %ss.', $translation->getOriginal());

tests/PoLoaderTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function testPoLoader()
1414
$loader = new PoLoader();
1515
$translations = $loader->loadFile(__DIR__.'/assets/translations.po');
1616

17-
$this->assertCount(13, $translations);
17+
$this->assertCount(14, $translations);
1818

1919
$array = $translations->getTranslations();
2020

@@ -31,6 +31,7 @@ public function testPoLoader()
3131
$this->translation11(array_shift($array));
3232
$this->translation12(array_shift($array));
3333
$this->translation13(array_shift($array));
34+
$this->translation14(array_shift($array));
3435

3536
$headers = $translations->getHeaders()->toArray();
3637

@@ -206,6 +207,16 @@ private function translation13(Translation $translation)
206207
$this->assertCount(0, $translation->getReferences());
207208
}
208209

210+
private function translation14(Translation $translation)
211+
{
212+
$this->assertSame('%s has been added to your cart.', $translation->getOriginal());
213+
$this->assertSame('%s have been added to your cart.', $translation->getPlural());
214+
$this->assertSame('%s has been added to your cart.', $translation->getTranslation());
215+
$this->assertSame(['%s have been added to your cart.'], $translation->getPluralTranslations());
216+
$this->assertCount(1, $translation->getComments());
217+
$this->assertCount(0, $translation->getReferences());
218+
}
219+
209220
public function stringDecodeProvider()
210221
{
211222
return [

tests/assets/translations.mo

123 Bytes
Binary file not shown.

tests/assets/translations.po

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,10 @@ msgid "Multibyte test"
7777
msgstr "日本人は日本で話される言語です!"
7878

7979
msgid "Tabulation test"
80-
msgstr "FIELD\tFIELD"
80+
msgstr "FIELD\tFIELD"
81+
82+
# Issue https://github.com/php-gettext/Gettext/issues/246
83+
msgid "%s has been added to your cart."
84+
msgid_plural "%s have been added to your cart."
85+
msgstr[0] "%s has been added to your cart."
86+
msgstr[1] "%s have been added to your cart."

0 commit comments

Comments
 (0)