Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit02e983e

Browse files
fallback to fallback_locale translation when requested translation line is empty (#34136)
1 parentd2e513a commit02e983e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

‎src/Illuminate/Translation/Translator.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function get($key, array $replace = [], $locale = null, $fallback = true)
122122
$locales =$fallback ?$this->localeArray($locale) : [$locale];
123123

124124
foreach ($localesas$locale) {
125-
if (!is_null($line =$this->getLine(
125+
if (!empty($line =$this->getLine(
126126
$namespace,$group,$locale,$item,$replace
127127
))) {
128128
return$line ??$key;

‎tests/Translation/TranslationTranslatorTest.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ public function testGetMethodProperlyLoadsAndRetrievesItemForFallback()
104104
$this->assertSame('foo',$t->get('foo::bar.foo'));
105105
}
106106

107+
publicfunctiontestGetMethodProperlyLoadsAndRetrievesItemForFallbackWhenLineIsEmpty()
108+
{
109+
$t =newTranslator($this->getLoader(),'en');
110+
$t->setFallback('lv');
111+
$t->getLoader()->shouldReceive('load')->once()->with('en','*','*')->andReturn([]);
112+
$t->getLoader()->shouldReceive('load')->once()->with('en','bar','foo')->andReturn(['baz' =>'']);
113+
$t->getLoader()->shouldReceive('load')->once()->with('lv','bar','foo')->andReturn(['foo' =>'foo','baz' =>'breeze :foo']);
114+
$this->assertSame('breeze bar',$t->get('foo::bar.baz', ['foo' =>'bar'],'en'));
115+
$this->assertSame('foo',$t->get('foo::bar.foo'));
116+
}
117+
107118
publicfunctiontestGetMethodProperlyLoadsAndRetrievesItemForGlobalNamespace()
108119
{
109120
$t =newTranslator($this->getLoader(),'en');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp