Skip to content

Commit

Permalink
Fix deprecation issue with translator (#42216)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints authored May 2, 2022
1 parent 832d1df commit f6e9f54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ protected function makeReplacements($line, array $replace)
$shouldReplace = [];

foreach ($replace as $key => $value) {
$shouldReplace[':'.Str::ucfirst($key)] = Str::ucfirst($value);
$shouldReplace[':'.Str::upper($key)] = Str::upper($value);
$shouldReplace[':'.Str::ucfirst($key ?? '')] = Str::ucfirst($value ?? '');
$shouldReplace[':'.Str::upper($key ?? '')] = Str::upper($value ?? '');
$shouldReplace[':'.$key] = $value;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Translation/TranslationTranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ public function testGetJsonForNonExistingReturnsSameKeyAndReplaces()
$this->assertSame('foo baz', $t->get('foo :message', ['message' => 'baz']));
}

public function testEmptyFallbacks()
{
$t = new Translator($this->getLoader(), 'en');
$t->getLoader()->shouldReceive('load')->once()->with('en', '*', '*')->andReturn([]);
$t->getLoader()->shouldReceive('load')->once()->with('en', 'foo :message', '*')->andReturn([]);
$this->assertSame('foo ', $t->get('foo :message', ['message' => null]));
}

protected function getLoader()
{
return m::mock(Loader::class);
Expand Down

0 comments on commit f6e9f54

Please sign in to comment.