8000 bug #38127 [Translator] Make sure a null locale is handled properly (… · fancyweb/symfony@785a066 · GitHub
[go: up one dir, main page]

Skip to content

Commit 785a066

Browse files
committed
bug symfony#38127 [Translator] Make sure a null locale is handled properly (jschaedl)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Translator] Make sure a null locale is handled properly | Q | A | ------------- | --- | Branch? | 4.4<!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix symfony#38124 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | - <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch master. --> Commits ------- 080ea5a [Translator] Make sure a null locale is handled properly
2 parents 948e107 + 080ea5a commit 785a066

File tree

2 files changed

+16
-3
lines changed
Collapse file tree

2 files changed

+16
-3
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919

2020
class TranslatorTest extends TestCase
2121
{
22+
private $defaultLocale;
23+
24+
protected function setUp(): void
25+
{
26+
$this->defaultLocale = \Locale::getDefault();
27+
\Locale::setDefault('en');
28+
}
29+
30+
protected function tearDown(): void
31+
{
32+
\Locale::setDefault($this->defaultLocale);
33+
}
34+
2235
/**
2336
* @dataProvider getInvalidLocalesTests
2437
*/
@@ -45,7 +58,7 @@ public function testConstructorWithoutLocale()
4558
{
4659
$translator = new Translator(null);
4760

48-
$this->assertNull($translator->getLocale());
61+
$this->assertSame('en', $translator->getLocale());
4962
}
5063

5164
public function testSetGetLocale()
@@ -87,7 +100,7 @@ public function testSetNullLocale()
87100
$translator = new Translator('en');
88101
$translator->setLocale(null);
89102

90-
$this->assertNull($translator->getLocale());
103+
$this->assertSame('en', $translator->getLocale());
91104
}
92105

93106
public function testGetCatalogue()

src/Symfony/Component/Translation/Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function setLocale($locale)
171171
*/
172172
public function getLocale()
173173
{
174-
return $this->locale;
174+
return $this->locale ?? \Locale::getDefault();
175175
}
176176

177177
/**

0 commit comments

Comments
 (0)
0