Skip to content

Commit

Permalink
Fix message parsing in Translator.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed May 22, 2017
1 parent ce63d42 commit 3fb8761
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/I18n/Translator.php
Expand Up @@ -131,7 +131,11 @@ public function translate($key, array $tokensValues = [])

// No or missing context, fallback to the key/first message
if ($context === null) {
$message = current($message['_context']);
if (isset($message['_context'][''])) {
$message = $message['_context'][''];
} else {
$message = current($message['_context']);
}
} elseif (!isset($message['_context'][$context])) {
$message = $key;
} elseif (is_string($message['_context'][$context]) &&
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/I18n/Parser/PoFileParserTest.php
Expand Up @@ -119,7 +119,7 @@ public function testParseContextOnSomeMessages()
$file = APP . 'Locale' . DS . 'en' . DS . 'context.po';
$messages = $parser->parse($file);

I18n::translator('default', 'en_US', function () use ($messages) {
I18n::translator('default', 'de_DE', function () use ($messages) {
$package = new Package('default');
$package->setMessages($messages);

Expand All @@ -131,7 +131,7 @@ public function testParseContextOnSomeMessages()
$this->assertSame('En resolved - context', $messages['Resolved']['_context']['Pay status']);

// Confirm actual behavior
I18n::locale('en_US');
I18n::locale('de_DE');
$this->assertSame('En cours', __('Pending'));
$this->assertSame('En cours - context', __x('Pay status', 'Pending'));
$this->assertSame('En resolved', __('Resolved'));
Expand Down

0 comments on commit 3fb8761

Please sign in to comment.