Skip to content
Permalink
Browse files

Empty message strings should return the key

context based messages should return the key when the translated value
is ''. This mirrors the behavior of context-less messages. Returning ''
was incorrectly added in #8932

Refs #10440
  • Loading branch information...
markstory committed May 5, 2017
1 parent bb9e73e commit b53308b5c2e27a689046df74fcbc4d669f7807f1
Showing with 5 additions and 3 deletions.
  1. +3 −2 src/I18n/Translator.php
  2. +2 −1 tests/TestCase/I18n/I18nTest.php
@@ -119,7 +119,6 @@ protected function getMessage($key)
public function translate($key, array $tokensValues = [])
{
$message = $this->getMessage($key);
if (!$message) {
// Fallback to the message key
$message = $key;
@@ -135,7 +134,9 @@ public function translate($key, array $tokensValues = [])
$message = current($message['_context']);
} elseif (!isset($message['_context'][$context])) {
$message = $key;
} elseif (!isset($message['_context'][$context])) {
} elseif (is_string($message['_context'][$context]) &&
strlen($message['_context'][$context]) === 0
) {
$message = $key;
} else {
$message = $message['_context'][$context];
@@ -441,7 +441,8 @@ public function testBasicContextFunctionNoString()
return $package;
});
$this->assertEquals('', __x('character', 'letter'));
$this->assertEquals('letter', __x('character', 'letter'));
$this->assertEquals('letter', __x('unknown', 'letter'));
}
/**

0 comments on commit b53308b

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