Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
+67 -15
View File
@@ -12,7 +12,6 @@
namespace Symfony\Component\Translation\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Translation\Exception\RuntimeException;
use Symfony\Component\Translation\Loader\ArrayLoader;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\Translator;
@@ -235,6 +234,42 @@ class TranslatorTest extends TestCase
$this->assertEquals('bar', $translator->trans('foo', [], 'resources'));
}
public function testTransWithIcuFallbackLocale()
{
$translator = new Translator('en_GB');
$translator->addLoader('array', new ArrayLoader());
$translator->addResource('array', ['foo' => 'foofoo'], 'en_GB');
$translator->addResource('array', ['bar' => 'foobar'], 'en_001');
$translator->addResource('array', ['baz' => 'foobaz'], 'en');
$this->assertSame('foofoo', $translator->trans('foo'));
$this->assertSame('foobar', $translator->trans('bar'));
$this->assertSame('foobaz', $translator->trans('baz'));
}
public function testTransWithIcuVariantFallbackLocale()
{
$translator = new Translator('en_GB_scouse');
$translator->addLoader('array', new ArrayLoader());
$translator->addResource('array', ['foo' => 'foofoo'], 'en_GB_scouse');
$translator->addResource('array', ['bar' => 'foobar'], 'en_GB');
$translator->addResource('array', ['baz' => 'foobaz'], 'en_001');
$translator->addResource('array', ['qux' => 'fooqux'], 'en');
$this->assertSame('foofoo', $translator->trans('foo'));
$this->assertSame('foobar', $translator->trans('bar'));
$this->assertSame('foobaz', $translator->trans('baz'));
$this->assertSame('fooqux', $translator->trans('qux'));
}
public function testTransWithIcuRootFallbackLocale()
{
$translator = new Translator('az_Cyrl');
$translator->addLoader('array', new ArrayLoader());
$translator->addResource('array', ['foo' => 'foofoo'], 'az_Cyrl');
$translator->addResource('array', ['bar' => 'foobar'], 'az');
$this->assertSame('foofoo', $translator->trans('foo'));
$this->assertSame('bar', $translator->trans('bar'));
}
/**
* @dataProvider getFallbackLocales
*/
@@ -319,12 +354,12 @@ class TranslatorTest extends TestCase
$resources = $translator->getCatalogue('en')->getResources();
$this->assertCount(1, $resources);
$this->assertContainsEquals(__DIR__.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'resources.yml', $resources);
$this->assertContains(__DIR__.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'resources.yml', $resources);
$resources = $translator->getCatalogue('en_GB')->getResources();
$this->assertCount(2, $resources);
$this->assertContainsEquals(__DIR__.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'empty.yml', $resources);
$this->assertContainsEquals(__DIR__.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'resources.yml', $resources);
$this->assertContains(__DIR__.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'empty.yml', $resources);
$this->assertContains(__DIR__.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'resources.yml', $resources);
}
/**
@@ -379,6 +414,7 @@ class TranslatorTest extends TestCase
/**
* @dataProvider getTransChoiceTests
* @group legacy
*/
public function testTransChoice($expected, $id, $translation, $number, $parameters, $locale, $domain)
{
@@ -391,6 +427,7 @@ class TranslatorTest extends TestCase
/**
* @dataProvider getInvalidLocalesTests
* @group legacy
*/
public function testTransChoiceInvalidLocale($locale)
{
@@ -404,6 +441,7 @@ class TranslatorTest extends TestCase
/**
* @dataProvider getValidLocalesTests
* @group legacy
*/
public function testTransChoiceValidLocale($locale)
{
@@ -485,7 +523,7 @@ class TranslatorTest extends TestCase
['Il y a 0 pomme', new StringClass('{0} There are no appless|{1} There is one apple|]1,Inf] There is %count% apples'), '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 0, [], 'fr', ''],
// Override %count% with a custom value
['Il y a quelques pommes', 'one: There is one apple|more: There are %count% apples', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 2, ['%count%' => 'quelques'], 'fr', ''],
['Il y a quelques pommes', 'one: There is one apple|more: There are %count% apples', 'one: Il y a %count% pomme|more: Il y a quelques pommes', 2, ['%count%' => 'quelques'], 'fr', ''],
];
}
@@ -523,6 +561,24 @@ class TranslatorTest extends TestCase
];
}
/**
* @requires extension intl
*/
public function testIntlFormattedDomain()
{
$translator = new Translator('en');
$translator->addLoader('array', new ArrayLoader());
$translator->addResource('array', ['some_message' => 'Hello %name%'], 'en');
$this->assertSame('Hello Bob', $translator->trans('some_message', ['%name%' => 'Bob']));
$translator->addResource('array', ['some_message' => 'Hi {name}'], 'en', 'messages+intl-icu');
$this->assertSame('Hi Bob', $translator->trans('some_message', ['%name%' => 'Bob']));
}
/**
* @group legacy
*/
public function testTransChoiceFallback()
{
$translator = new Translator('ru');
@@ -533,6 +589,9 @@ class TranslatorTest extends TestCase
$this->assertEquals('10 things', $translator->transChoice('some_message2', 10, ['%count%' => 10]));
}
/**
* @group legacy
*/
public function testTransChoiceFallbackBis()
{
$translator = new Translator('ru');
@@ -543,6 +602,9 @@ class TranslatorTest extends TestCase
$this->assertEquals('10 things', $translator->transChoice('some_message2', 10, ['%count%' => 10]));
}
/**
* @group legacy
*/
public function testTransChoiceFallbackWithNoTranslation()
{
$translator = new Translator('ru');
@@ -553,16 +615,6 @@ class TranslatorTest extends TestCase
// unchanged if it can't be found
$this->assertEquals('some_message2', $translator->transChoice('some_message2', 10, ['%count%' => 10]));
}
public function testMissingLoaderForResourceError()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('No loader is registered for the "twig" format when loading the "messages.en.twig" resource.');
$translator = new Translator('en');
$translator->addResource('twig', 'messages.en.twig', 'en');
$translator->getCatalogue('en');
}
}
class StringClass