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

[10.x] Officially support floats in trans_choice and Translator::choice #49693

Merged
merged 1 commit into from Jan 15, 2024
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/Contracts/Translation/Translator.php
Expand Up @@ -18,7 +18,7 @@ public function get($key, array $replace = [], $locale = null);
* Get a translation according to an integer value.
*
* @param string $key
* @param \Countable|int|array $number
* @param \Countable|int|float|array $number
* @param array $replace
* @param string|null $locale
* @return string
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/helpers.php
Expand Up @@ -929,7 +929,7 @@ function trans($key = null, $replace = [], $locale = null)
* Translates the given message based on a count.
*
* @param string $key
* @param \Countable|int|array $number
* @param \Countable|int|float|array $number
* @param array $replace
* @param string|null $locale
* @return string
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Translation/PotentiallyTranslatedString.php
Expand Up @@ -57,7 +57,7 @@ public function translate($replace = [], $locale = null)
/**
* Translates the string based on a count.
*
* @param \Countable|int|array $number
* @param \Countable|int|float|array $number
* @param array $replace
* @param string|null $locale
* @return $this
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Translation/Translator.php
Expand Up @@ -183,7 +183,7 @@ public function get($key, array $replace = [], $locale = null, $fallback = true)
* Get a translation according to an integer value.
*
* @param string $key
* @param \Countable|int|array $number
* @param \Countable|int|float|array $number
* @param array $replace
* @param string|null $locale
* @return string
Expand Down
12 changes: 11 additions & 1 deletion tests/Translation/TranslationTranslatorTest.php
Expand Up @@ -123,7 +123,7 @@ public function testGetMethodProperlyLoadsAndRetrievesItemForGlobalNamespace()
$this->assertSame('breeze bar', $t->get('foo.bar', ['foo' => 'bar']));
}

public function testChoiceMethodProperlyLoadsAndRetrievesItem()
public function testChoiceMethodProperlyLoadsAndRetrievesItemForAnInt()
{
$t = $this->getMockBuilder(Translator::class)->onlyMethods(['get'])->setConstructorArgs([$this->getLoader(), 'en'])->getMock();
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo(['replace']), $this->equalTo('en'))->willReturn('line');
Expand All @@ -133,6 +133,16 @@ public function testChoiceMethodProperlyLoadsAndRetrievesItem()
$t->choice('foo', 10, ['replace']);
}

public function testChoiceMethodProperlyLoadsAndRetrievesItemForAFloat()
{
$t = $this->getMockBuilder(Translator::class)->onlyMethods(['get'])->setConstructorArgs([$this->getLoader(), 'en'])->getMock();
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo(['replace']), $this->equalTo('en'))->willReturn('line');
$t->setSelector($selector = m::mock(MessageSelector::class));
$selector->shouldReceive('choose')->once()->with('line', 1.2, 'en')->andReturn('choiced');

$t->choice('foo', 1.2, ['replace']);
}

public function testChoiceMethodProperlyCountsCollectionsAndLoadsAndRetrievesItem()
{
$t = $this->getMockBuilder(Translator::class)->onlyMethods(['get'])->setConstructorArgs([$this->getLoader(), 'en'])->getMock();
Expand Down