Skip to content

Commit b10b6ae

Browse files
committed
[Translation] deprecate passing a null locale
1 parent 6811aaa commit b10b6ae

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/Symfony/Component/Translation/MessageCatalogue.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
3232
*/
3333
public function __construct(?string $locale, array $messages = [])
3434
{
35+
if (null === $locale) {
36+
@trigger_error(sprintf('Passing "null" to "$locale" in %s::%s has been deprecated since Symfony 4.4 and will throw in 5.0.', __CLASS__, __METHOD__), E_USER_DEPRECATED);
37+
}
38+
3539
$this->locale = $locale;
3640
$this->messages = $messages;
3741
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@ public function testAddResourceValidLocales($locale)
190190
$this->addToAssertionCount(1);
191191
}
192192

193+
/**
194+
* @group legacy
195+
* @expectedDeprecation Passing "null" to "$locale" in Symfony\Component\Translation\Translator::Symfony\Component\Translation\Translator::addResource has been deprecated since Symfony 4.4 and will throw in 5.0.
196+
*/
197+
public function testAddResourceNull()
198+
{
199+
$translator = new Translator('fr');
200+
$translator->addResource('array', ['foo' => 'foofoo'], null);
201+
// no assertion. this method just asserts that no exception is thrown
202+
$this->addToAssertionCount(1);
203+
}
204+
193205
public function testAddResourceAfterTrans()
194206
{
195207
$translator = new Translator('fr');
@@ -527,7 +539,6 @@ public function getValidLocalesTests()
527539
{
528540
return [
529541
[''],
530-
[null],
531542
['fr'],
532543
['francais'],
533544
['FR'],

src/Symfony/Component/Translation/Translator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ public function addResource($format, $resource, $locale, $domain = null)
132132
$domain = 'messages';
133133
}
134134

135+
if (null === $locale) {
136+
@trigger_error(sprintf('Passing "null" to "$locale" in %s::%s has been deprecated since Symfony 4.4 and will throw in 5.0.', __CLASS__, __METHOD__), E_USER_DEPRECATED);
137+
}
138+
135139
$this->assertValidLocale($locale);
136140

137141
$this->resources[$locale][] = [$format, $resource, $domain];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy