Skip to content
Permalink
Browse files

Fix MoParser if an message exist with and without context. And it is …

…also more inline with the PoFileParser.
  • Loading branch information...
Iandenh committed Oct 24, 2018
1 parent 6fa82ae commit 0516ca1d629051733c0d6a3b7c742989017ba4cf
Showing with 67 additions and 18 deletions.
  1. +2 −2 src/I18n/Parser/MoFileParser.php
  2. +65 −16 tests/TestCase/I18n/Parser/MoFileParserTest.php
@@ -134,9 +134,9 @@ public function parse($resource)
continue;
}
$messages[$singularId] = $singular;
$messages[$singularId]['_context'][''] = $singular;
if ($pluralId !== null) {
$messages[$pluralId] = $plurals;
$messages[$pluralId]['_context'][''] = $plurals;
}
}
@@ -12,6 +12,7 @@
* @since 3.0.0
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Test\TestCase\I18n\Parser;
use Cake\I18n\Parser\MoFileParser;
@@ -35,12 +36,24 @@ public function testParse()
$messages = $parser->parse($file);
$this->assertCount(3, $messages);
$expected = [
'%d = 1 (from core)' => '%d = 1 (from core translated)',
'%d = 1 (from core)' => [
'_context' => [
'' => '%d = 1 (from core translated)'
]
],
'%d = 0 or > 1 (from core)' => [
'%d = 1 (from core translated)',
'%d = 0 or > 1 (from core translated)'
'_context' => [
'' => [
'%d = 1 (from core translated)',
'%d = 0 or > 1 (from core translated)'
]
]
],
'Plural Rule 1 (from core)' => 'Plural Rule 1 (from core translated)'
'Plural Rule 1 (from core)' => [
'_context' => [
'' => 'Plural Rule 1 (from core translated)'
]
]
];
$this->assertEquals($expected, $messages);
}
@@ -57,10 +70,22 @@ public function testParse0()
$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)',
'Plural Rule 1 (from core)' => [
'_context' => [
'' => 'Plural Rule 0 (from core translated)'
]
],
'%d = 1 (from core)' => [
'_context' => [
'' => '%d ends with any # (from core translated)'
]
],
'%d = 0 or > 1 (from core)' => [
'%d ends with any # (from core translated)',
'_context' => [
'' => [
'%d ends with any # (from core translated)',
]
]
],
];
$this->assertEquals($expected, $messages);
@@ -78,13 +103,25 @@ public function testParse2()
$messages = $parser->parse($file);
$this->assertCount(3, $messages);
$expected = [
'%d = 1 (from core)' => '%d is 1 (from core translated)',
'%d = 1 (from core)' => [
'_context' => [
'' => '%d is 1 (from core translated)'
]
],
'%d = 0 or > 1 (from core)' => [
'%d is 1 (from core translated)',
'%d ends in 2-4, not 12-14 (from core translated)',
'%d everything else (from core translated)'
'_context' => [
'' => [
'%d is 1 (from core translated)',
'%d ends in 2-4, not 12-14 (from core translated)',
'%d everything else (from core translated)'
]
]
],
'Plural Rule 1 (from core)' => 'Plural Rule 9 (from core translated)'
'Plural Rule 1 (from core)' => [
'_context' => [
'' => 'Plural Rule 9 (from core translated)'
]
]
];
$this->assertEquals($expected, $messages);
}
@@ -101,7 +138,11 @@ public function testParseFull()
$messages = $parser->parse($file);
$this->assertCount(5, $messages);
$expected = [
'Plural Rule 1' => 'Plural Rule 1 (translated)',
'Plural Rule 1' => [
'_context' => [
'' => 'Plural Rule 1 (translated)'
]
],
'%d = 1' => [
'_context' => [
'This is the context' => 'First Context trasnlation',
@@ -116,10 +157,18 @@ public function testParseFull()
]
]
],
'%-5d = 1' => '%-5d = 1 (translated)',
'%-5d = 1' => [
'_context' => [
'' => '%-5d = 1 (translated)'
]
],
'%-5d = 0 or > 1' => [
'%-5d = 1 (translated)',
'%-5d = 0 or > 1 (translated)'
'_context' => [
'' => [
'%-5d = 1 (translated)',
'%-5d = 0 or > 1 (translated)'
]
]
]
];
$this->assertEquals($expected, $messages);

0 comments on commit 0516ca1

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