Skip to content
Permalink
Browse files

Fix empty translations

  • Loading branch information...
berarma committed Jul 27, 2017
1 parent c75f2e7 commit 0c7daf1a3c6bdf4168315fec26e496057fa06c3d
Showing with 14 additions and 2 deletions.
  1. +1 −1 src/I18n/Translator.php
  2. +12 −0 tests/TestCase/I18n/I18nTest.php
  3. +1 −1 tests/test_app/TestApp/Locale/en/default.po
@@ -174,7 +174,7 @@ protected function resolveContext($key, $message, array $vars)
// No or missing context, fallback to the key/first message
if ($context === null) {
if (isset($message['_context'][''])) {
return $message['_context'][''];
return $message['_context'][''] === '' ? $key : $message['_context'][''];
}
return current($message['_context']);
@@ -844,4 +844,16 @@ public function testFallbackTranslatorWithFactory()
$this->assertEquals('Le moo', $translator->translate('Cow'));
$this->assertEquals('Le bark', $translator->translate('Dog'));
}
/**
* Tests the __() function on empty translations
*
* @return void
*/
public function testEmptyTranslationString()
{
I18n::defaultFormatter('sprintf');
$result = __('No translation needed');
$this->assertEquals('No translation needed', $result);
}
}
@@ -32,7 +32,7 @@ msgstr "This is a multiline translation\n"
"This is the third line.\n"
"This is the forth line. (translated)"

msgid "No Translation needed"
msgid "No translation needed"
msgstr ""

msgid "test"

0 comments on commit 0c7daf1

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