8000 Make Translator::getLocale() behave the same like TranslatorTrait::ge… · symfony/symfony@6de7ed8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6de7ed8

Browse files
committed
Make Translator::getLocale() behave the same like TranslatorTrait::getLocale()
1 parent c56a621 commit 6de7ed8

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Symfony/Component/Translation/Tests/TranslatorTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ public function getInvalidLocalesTests()
510510
public function getValidLocalesTests()
511511
{
512512
return [
513-
[''],
514513
['fr'],
515514
['francais'],
516515
['FR'],

src/Symfony/Component/Translation/Translator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ class Translator implements TranslatorInterface, TranslatorBagInterface, LocaleA
9191
*/
9292
public function __construct(string $locale, MessageFormatterInterface $formatter = null, string $cacheDir = null, bool $debug = false, array $cacheVary = [])
9393
{
94+
if ('' === $locale) {
95+
trigger_deprecation('symfony/translator', '5.2', sprintf('Passing "" as the $locale argument to %s::%s() is deprecated, it will throw an InvalidArgumentException in version 6.0.', get_class($this), __METHOD__));
96+
}
97+
9498
$this->setLocale($locale);
9599

96100
if (null === $formatter) {
@@ -158,7 +162,7 @@ public function setLocale(string $locale)
158162
*/
159163
public function getLocale()
160164
{
161-
return $this->locale;
165+
return $this->locale ?: \Locale::getDefault();
162166
}
163167

164168
/**

0 commit comments

Comments
 (0)
0