deprecate support for null locales
This commit is contained in:
parent
5a753b1428
commit
e6b6a9d33a
|
@ -189,6 +189,11 @@ Stopwatch
|
||||||
|
|
||||||
* Deprecated passing `null` as 1st (`$id`) argument of `Section::get()` method, pass a valid child section identifier instead.
|
* Deprecated passing `null` as 1st (`$id`) argument of `Section::get()` method, pass a valid child section identifier instead.
|
||||||
|
|
||||||
|
Translation
|
||||||
|
-----------
|
||||||
|
|
||||||
|
* Deprecated support for using `null` as the locale in `Translator`.
|
||||||
|
|
||||||
TwigBridge
|
TwigBridge
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
|
|
@ -518,6 +518,7 @@ Stopwatch
|
||||||
Translation
|
Translation
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
* Support for using `null` as the locale in `Translator` has been removed.
|
||||||
* The `FileDumper::setBackup()` method has been removed.
|
* The `FileDumper::setBackup()` method has been removed.
|
||||||
* The `TranslationWriter::disableBackup()` method has been removed.
|
* The `TranslationWriter::disableBackup()` method has been removed.
|
||||||
* The `TranslatorInterface` has been removed in favor of `Symfony\Contracts\Translation\TranslatorInterface`
|
* The `TranslatorInterface` has been removed in favor of `Symfony\Contracts\Translation\TranslatorInterface`
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
4.4.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* deprecated support for using `null` as the locale in `Translator`
|
||||||
|
|
||||||
4.3.0
|
4.3.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,12 @@ class TranslatorTest extends TestCase
|
||||||
{
|
{
|
||||||
$translator = new Translator($locale);
|
$translator = new Translator($locale);
|
||||||
|
|
||||||
$this->assertEquals($locale, $translator->getLocale());
|
$this->assertSame($locale, $translator->getLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
*/
|
||||||
public function testConstructorWithoutLocale()
|
public function testConstructorWithoutLocale()
|
||||||
{
|
{
|
||||||
$translator = new Translator(null);
|
$translator = new Translator(null);
|
||||||
|
@ -75,6 +78,17 @@ class TranslatorTest extends TestCase
|
||||||
$this->assertEquals($locale, $translator->getLocale());
|
$this->assertEquals($locale, $translator->getLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
*/
|
||||||
|
public function testSetNullLocale()
|
||||||
|
{
|
||||||
|
$translator = new Translator('en');
|
||||||
|
$translator->setLocale(null);
|
||||||
|
|
||||||
|
$this->assertNull($translator->getLocale());
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetCatalogue()
|
public function testGetCatalogue()
|
||||||
{
|
{
|
||||||
$translator = new Translator('en');
|
$translator = new Translator('en');
|
||||||
|
@ -158,6 +172,17 @@ class TranslatorTest extends TestCase
|
||||||
$this->addToAssertionCount(1);
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
*/
|
||||||
|
public function testSetNullFallbackLocale()
|
||||||
|
{
|
||||||
|
$translator = new Translator('en');
|
||||||
|
$translator->setFallbackLocales(['fr', null]);
|
||||||
|
// no assertion. this method just asserts that no exception is thrown
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
public function testTransWithFallbackLocale()
|
public function testTransWithFallbackLocale()
|
||||||
{
|
{
|
||||||
$translator = new Translator('fr_FR');
|
$translator = new Translator('fr_FR');
|
||||||
|
@ -184,9 +209,6 @@ class TranslatorTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testAddResourceValidLocales($locale)
|
public function testAddResourceValidLocales($locale)
|
||||||
{
|
{
|
||||||
if (null === $locale) {
|
|
||||||
$this->markTestSkipped('null is not a valid locale');
|
|
||||||
}
|
|
||||||
$translator = new Translator('fr');
|
$translator = new Translator('fr');
|
||||||
$translator->addResource('array', ['foo' => 'foofoo'], $locale);
|
$translator->addResource('array', ['foo' => 'foofoo'], $locale);
|
||||||
// no assertion. this method just asserts that no exception is thrown
|
// no assertion. this method just asserts that no exception is thrown
|
||||||
|
@ -382,9 +404,6 @@ class TranslatorTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testTransValidLocale($locale)
|
public function testTransValidLocale($locale)
|
||||||
{
|
{
|
||||||
if (null === $locale) {
|
|
||||||
$this->markTestSkipped('null is not a valid locale');
|
|
||||||
}
|
|
||||||
$translator = new Translator($locale);
|
$translator = new Translator($locale);
|
||||||
$translator->addLoader('array', new ArrayLoader());
|
$translator->addLoader('array', new ArrayLoader());
|
||||||
$translator->addResource('array', ['test' => 'OK'], $locale);
|
$translator->addResource('array', ['test' => 'OK'], $locale);
|
||||||
|
@ -458,6 +477,20 @@ class TranslatorTest extends TestCase
|
||||||
$this->addToAssertionCount(1);
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
*/
|
||||||
|
public function testTransChoiceNullLocale()
|
||||||
|
{
|
||||||
|
$translator = new Translator('en');
|
||||||
|
$translator->addLoader('array', new ArrayLoader());
|
||||||
|
$translator->addResource('array', ['foo' => 'foofoo'], 'en');
|
||||||
|
|
||||||
|
$translator->transChoice('foo', 1, [], '', null);
|
||||||
|
// no assertion. this method just asserts that no exception is thrown
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
public function getTransFileTests()
|
public function getTransFileTests()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -552,7 +585,6 @@ class TranslatorTest extends TestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[''],
|
[''],
|
||||||
[null],
|
|
||||||
['fr'],
|
['fr'],
|
||||||
['francais'],
|
['francais'],
|
||||||
['FR'],
|
['FR'],
|
||||||
|
|
|
@ -88,7 +88,11 @@ class Translator implements LegacyTranslatorInterface, TranslatorInterface, Tran
|
||||||
*/
|
*/
|
||||||
public function __construct(?string $locale, MessageFormatterInterface $formatter = null, string $cacheDir = null, bool $debug = false)
|
public function __construct(?string $locale, MessageFormatterInterface $formatter = null, string $cacheDir = null, bool $debug = false)
|
||||||
{
|
{
|
||||||
$this->setLocale($locale);
|
if (null === $locale) {
|
||||||
|
@trigger_error(sprintf('Passing "null" as the $locale argument to %s() is deprecated since Symfony 4.4.', __METHOD__), E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setLocale($locale, false);
|
||||||
|
|
||||||
if (null === $formatter) {
|
if (null === $formatter) {
|
||||||
$formatter = new MessageFormatter();
|
$formatter = new MessageFormatter();
|
||||||
|
@ -151,6 +155,10 @@ class Translator implements LegacyTranslatorInterface, TranslatorInterface, Tran
|
||||||
*/
|
*/
|
||||||
public function setLocale($locale)
|
public function setLocale($locale)
|
||||||
{
|
{
|
||||||
|
if (null === $locale && (2 > \func_num_args() || func_get_arg(1))) {
|
||||||
|
@trigger_error(sprintf('Passing "null" as the $locale argument to %s() is deprecated since Symfony 4.4.', __METHOD__), E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertValidLocale($locale);
|
$this->assertValidLocale($locale);
|
||||||
$this->locale = $locale;
|
$this->locale = $locale;
|
||||||
}
|
}
|
||||||
|
@ -176,6 +184,9 @@ class Translator implements LegacyTranslatorInterface, TranslatorInterface, Tran
|
||||||
$this->catalogues = [];
|
$this->catalogues = [];
|
||||||
|
|
||||||
foreach ($locales as $locale) {
|
foreach ($locales as $locale) {
|
||||||
|
if (null === $locale) {
|
||||||
|
@trigger_error(sprintf('Passing "null" as the $locale argument to %s() is deprecated since Symfony 4.4.', __METHOD__), E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
$this->assertValidLocale($locale);
|
$this->assertValidLocale($locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue