Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Fix for empty fallback_locale #34136

Merged
merged 1 commit into from Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Translation/Translator.php
Expand Up @@ -122,7 +122,7 @@ public function get($key, array $replace = [], $locale = null, $fallback = true)
$locales = $fallback ? $this->localeArray($locale) : [$locale];

foreach ($locales as $locale) {
if (! is_null($line = $this->getLine(
if (! empty($line = $this->getLine(
$namespace, $group, $locale, $item, $replace
))) {
return $line ?? $key;
Expand Down
11 changes: 11 additions & 0 deletions tests/Translation/TranslationTranslatorTest.php
Expand Up @@ -104,6 +104,17 @@ public function testGetMethodProperlyLoadsAndRetrievesItemForFallback()
$this->assertSame('foo', $t->get('foo::bar.foo'));
}

public function testGetMethodProperlyLoadsAndRetrievesItemForFallbackWhenLineIsEmpty()
{
$t = new Translator($this->getLoader(), 'en');
$t->setFallback('lv');
$t->getLoader()->shouldReceive('load')->once()->with('en', '*', '*')->andReturn([]);
$t->getLoader()->shouldReceive('load')->once()->with('en', 'bar', 'foo')->andReturn(['baz' => '']);
$t->getLoader()->shouldReceive('load')->once()->with('lv', 'bar', 'foo')->andReturn(['foo' => 'foo', 'baz' => 'breeze :foo']);
$this->assertSame('breeze bar', $t->get('foo::bar.baz', ['foo' => 'bar'], 'en'));
$this->assertSame('foo', $t->get('foo::bar.foo'));
}

public function testGetMethodProperlyLoadsAndRetrievesItemForGlobalNamespace()
{
$t = new Translator($this->getLoader(), 'en');
Expand Down