Skip to content
Permalink
Browse files

Fixed translations for empty value.

  • Loading branch information...
bbankowski committed May 13, 2019
1 parent 4ab809c commit 41be76d3fc8312b6961a52ed5102dfe82439694d
Showing with 17 additions and 1 deletion.
  1. +1 −1 src/Ouzo/Core/Translator.php
  2. +16 −0 test/src/Ouzo/Core/TranslatorTest.php
@@ -24,7 +24,7 @@ public function __construct($language, $labels)
public function translate($key, $params = [])
{
$explodedKey = explode('.', $key);
$translation = Arrays::getNestedValue($this->_labels, $explodedKey) ?: $key;
$translation = Arrays::getNestedValue($this->_labels, $explodedKey) ?? $key;
return $this->localize(Strings::sprintAssoc($translation, $params));
}
@@ -26,6 +26,22 @@ public function shouldTranslateSimpleKey()
$this->assertEquals('translation', $translation);
}
/**
* @test
*/
public function shouldTranslateSimpleKeyWhenValueIsEmpty()
{
//given
$labels = ['key' => ''];
$translator = new Translator('en', $labels);
//when
$translation = $translator->translate('key');
//then
$this->assertEquals('', $translation);
}
/**
* @test
*/

0 comments on commit 41be76d

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