diff --git a/src/Translator.php b/src/Translator.php index 6440b29..d042da6 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -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]; } diff --git a/tests/MoFilesTest.php b/tests/MoFilesTest.php index cd92519..f2b7785 100644 --- a/tests/MoFilesTest.php +++ b/tests/MoFilesTest.php @@ -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'; } diff --git a/tests/data/lessplurals.mo b/tests/data/lessplurals.mo new file mode 100644 index 0000000..5288d9e Binary files /dev/null and b/tests/data/lessplurals.mo differ