Skip to content

Commit

Permalink
MoFileParser support Plural-Forms: nplurals=1; plural=0;
Browse files Browse the repository at this point in the history
  • Loading branch information
nojimage committed Jul 6, 2017
1 parent 02c51aa commit 3df3ccb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/I18n/Parser/MoFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
21 changes: 21 additions & 0 deletions tests/TestCase/I18n/Parser/MoFileParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 3df3ccb

Please sign in to comment.