Skip to content

Commit

Permalink
localeForChoice returns fallback if key doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanvdlugt committed Jul 31, 2024
1 parent 516bf8d commit d4e9f5a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Illuminate/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function get($key, array $replace = [], $locale = null, $fallback = true)
public function choice($key, $number, array $replace = [], $locale = null)
{
$line = $this->get(
$key, $replace, $locale = $this->localeForChoice($locale)
$key, $replace, $locale = $this->localeForChoice($key, $locale)
);

// If the given "number" is actually an array or countable we will simply count the
Expand All @@ -211,12 +211,21 @@ public function choice($key, $number, array $replace = [], $locale = null)
/**
* Get the proper locale for a choice operation.
*
* @param string $key
* @param string|null $locale
* @return string
*/
protected function localeForChoice($locale)
protected function localeForChoice($key, $locale)
{
return $locale ?: $this->locale ?: $this->fallback;
if ($locale && $this->hasForLocale($key, $locale)) {
return $locale;
}

if ($this->hasForLocale($key, $this->locale)) {
return $this->locale;
}

return $this->fallback;
}

/**
Expand Down

0 comments on commit d4e9f5a

Please sign in to comment.