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

[11.X] Fix 0 being treated as falsey when making translation replacements #53193

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function get($key, array $replace = [], $locale = null, $fallback = true)
// If the line doesn't exist, we will return back the key which was requested as
// that will be quick to spot in the UI if language keys are wrong or missing
// from the application's language files. Otherwise we can return the line.
return $this->makeReplacements($line ?: $key, $replace);
return $this->makeReplacements($line !== null ? $line : $key, $replace);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/Translation/TranslationTranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ public function testDetermineLocalesUsingMethod()
$this->assertSame('foo', $t->get('foo'));
}

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

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