Skip to content
Permalink
Browse files

MoFileParser support Plural-Forms: nplurals=1; plural=0;

  • Loading branch information...
nojimage committed Jul 6, 2017
1 parent 02c51aa commit 3df3ccbe699e0f6214d4c27f67aeb4dfbe99f3ff
Showing with 22 additions and 1 deletion.
  1. +1 −1 src/I18n/Parser/MoFileParser.php
  2. +21 −0 tests/TestCase/I18n/Parser/MoFileParserTest.php
@@ -119,7 +119,7 @@ public function parse($resource)
fseek($stream, $offset);
$translated = fread($stream, $length);
if (strpos($translated, "\000") !== false) {
if ($pluralId !== null || strpos($translated, "\000") !== false) {
$translated = explode("\000", $translated);
$plurals = $pluralId !== null ? array_map('stripcslashes', $translated) : null;
$translated = $translated[0];
@@ -45,6 +45,27 @@ public function testParse()
$this->assertEquals($expected, $messages);
}
/**
* Tests parsing a file with single form plurals
*
* @return void
*/
public function testParse0()
{
$parser = new MoFileParser;
$file = APP . 'Locale' . DS . 'rule_0_mo' . DS . 'core.mo';
$messages = $parser->parse($file);
$this->assertCount(3, $messages);
$expected = [
'Plural Rule 1 (from core)' => 'Plural Rule 0 (from core translated)',
'%d = 1 (from core)' => '%d ends with any # (from core translated)',
'%d = 0 or > 1 (from core)' => [
'%d ends with any # (from core translated)',
],
];
$this->assertEquals($expected, $messages);
}
/**
* Tests parsing a file with larger plural forms
*

0 comments on commit 3df3ccb

Please sign in to comment.
You can’t perform that action at this time.