Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6de7ed8

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

File tree

Expand file treeCollapse file tree

2 files changed

+5
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+5
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/TranslatorTest.php
-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Translator.php
+5-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.