Skip to content

Commit

Permalink
Correctly handle when mo file contains less plurals than formula says
Browse files Browse the repository at this point in the history
Fixes #18

Signed-off-by: Michal Čihař <[email protected]>
  • Loading branch information
nijel committed May 23, 2017
1 parent 5c0405e commit 690e70b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ public function ngettext($msgid, $msgidPlural, $number)
$result = $this->cache_translations[$key];
$list = explode(chr(0), $result);

if (! isset($list[$select])) {
return $list[0];
}
return $list[$select];
}

Expand Down
6 changes: 3 additions & 3 deletions tests/MoFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public function testMoFilePlurals($filename)
{
$parser = new PhpMyAdmin\MoTranslator\Translator($filename);
$expected_2 = '%d sekundy';
if (strpos($filename, 'plurals.mo') !== false || strpos($filename, 'noheader.mo') !== false) {
$expected_0 = '%d sekundy';
} elseif (strpos($filename, 'invalid-formula.mo') !== false) {
if (strpos($filename, 'invalid-formula.mo') !== false || strpos($filename, 'lessplurals.mo') !== false) {
$expected_0 = '%d sekunda';
$expected_2 = '%d sekunda';
} elseif (strpos($filename, 'plurals.mo') !== false || strpos($filename, 'noheader.mo') !== false) {
$expected_0 = '%d sekundy';
} else {
$expected_0 = '%d sekund';
}
Expand Down
Binary file added tests/data/lessplurals.mo
Binary file not shown.

0 comments on commit 690e70b

Please sign in to comment.