Skip to content

Commit

Permalink
Merge branch '5.4' into 6.0
Browse files Browse the repository at this point in the history
* 5.4:
  Fix tests on PHP 8.1
  [Cache] Fix memory leak
  [Config] Add missing use statement in generated config builder classes
  [DependencyInjection] fix inlining when non-shared services are involved
  [FrameworkBundle] fix deprecation message
  [DoctrineBridge] add support for the JSON type
  [PHPUnitBridge] Fix Uncaught ValueError
  [HttpClient] Implement ResetInterface for all http clients
  [HttpKernel] allow ignoring kernel.reset methods that don't exist
  [FrameworkBundle] fix registering late resettable services
  [Validator] Missing translations for Greek (el)
  translate for japanese 101,102,103
  Use symfony-*-bridge instead of symfony-bridge for component bridges
  Fix Loco Provider
  [HttpClient] Curl http client has to reinit curl multi handle on reset
  [SecurityBundle] Fix compat with symfony/security-core:^6 (ter)
  [Validator] Add Swedish translation for issue #43737
  • Loading branch information
nicolas-grekas committed Nov 12, 2021
2 parents e9044a6 + 70f9cd0 commit dcc3b6e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 19 deletions.
3 changes: 1 addition & 2 deletions Command/TranslationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ private function readLocalTranslations(array $locales, array $domains, array $tr

if ($domains) {
foreach ($domains as $domain) {
$catalogue = $this->filterCatalogue($catalogue, $domain);
$bag->addCatalogue($catalogue);
$bag->addCatalogue($this->filterCatalogue($catalogue, $domain));
}
} else {
$bag->addCatalogue($catalogue);
Expand Down
71 changes: 62 additions & 9 deletions Tests/Command/TranslationPullCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,30 @@ public function testPullNewXlf20Messages()
public function testPullForceMessages()
{
$arrayLoader = new ArrayLoader();
$filenameEn = $this->createFile();
$filenameFr = $this->createFile(['note' => 'NOTE'], 'fr');
$filenameMessagesEn = $this->createFile(['note' => 'NOTE'], 'en');
$filenameMessagesFr = $this->createFile(['note' => 'NOTE'], 'fr');
$filenameValidatorsEn = $this->createFile(['foo.error' => 'Wrong value'], 'en', 'validators.%locale%.xlf');
$filenameValidatorsFr = $this->createFile(['foo.error' => 'Valeur erronée'], 'fr', 'validators.%locale%.xlf');
$locales = ['en', 'fr'];
$domains = ['messages'];
$domains = ['messages', 'validators'];

$providerReadTranslatorBag = new TranslatorBag();
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
'note' => 'UPDATED NOTE',
'new.foo' => 'newFoo',
], 'en'));
], 'en', 'messages'));
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
'note' => 'NOTE MISE À JOUR',
'new.foo' => 'nouveauFoo',
], 'fr'));
], 'fr', 'messages'));
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
'foo.error' => 'Bad value',
'bar.error' => 'Bar error',
], 'en', 'validators'));
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
'foo.error' => 'Valeur invalide',
'bar.error' => 'Bar erreur',
], 'fr', 'validators'));

$provider = $this->createMock(ProviderInterface::class);
$provider->expects($this->once())
Expand All @@ -222,9 +232,9 @@ public function testPullForceMessages()
->willReturn('null://default');

$tester = $this->createCommandTester($provider, $locales, $domains);
$tester->execute(['--locales' => ['en', 'fr'], '--domains' => ['messages'], '--force' => true]);
$tester->execute(['--locales' => $locales, '--domains' => $domains, '--force' => true]);

$this->assertStringContainsString('[OK] Local translations has been updated from "null" (for "en, fr" locale(s), and "messages" domain(s)).', trim($tester->getDisplay()));
$this->assertStringContainsString('[OK] Local translations has been updated from "null" (for "en, fr" locale(s), and "messages, validators" domain(s)).', trim($tester->getDisplay()));
$this->assertXmlStringEqualsXmlString(<<<XLIFF
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
Expand All @@ -245,7 +255,7 @@ public function testPullForceMessages()
</file>
</xliff>
XLIFF
, file_get_contents($filenameEn));
, file_get_contents($filenameMessagesEn));
$this->assertXmlStringEqualsXmlString(<<<XLIFF
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
Expand All @@ -266,7 +276,50 @@ public function testPullForceMessages()
</file>
</xliff>
XLIFF
, file_get_contents($filenameFr));
, file_get_contents($filenameMessagesFr));

$this->assertXmlStringEqualsXmlString(<<<XLIFF
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" target-language="en" datatype="plaintext" original="file.ext">
<header>
<tool tool-id="symfony" tool-name="Symfony"/>
</header>
<body>
<trans-unit id="kA4akVr" resname="foo.error">
<source>foo.error</source>
<target>Bad value</target>
</trans-unit>
<trans-unit id="OcBtn3X" resname="bar.error">
<source>bar.error</source>
<target>Bar error</target>
</trans-unit>
</body>
</file>
</xliff>
XLIFF
, file_get_contents($filenameValidatorsEn));
$this->assertXmlStringEqualsXmlString(<<<XLIFF
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" target-language="fr" datatype="plaintext" original="file.ext">
<header>
<tool tool-id="symfony" tool-name="Symfony"/>
</header>
<body>
<trans-unit id="kA4akVr" resname="foo.error">
<source>foo.error</source>
<target>Valeur invalide</target>
</trans-unit>
<trans-unit id="OcBtn3X" resname="bar.error">
<source>bar.error</source>
<target>Bar erreur</target>
</trans-unit>
</body>
</file>
</xliff>
XLIFF
, file_get_contents($filenameValidatorsFr));
}

/**
Expand Down
26 changes: 18 additions & 8 deletions Tests/Command/TranslationPushCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,32 @@ public function testPushNewMessages()
public function testPushForceMessages()
{
$xliffLoader = new XliffFileLoader();
$filenameEn = $this->createFile([
$filenameMessagesEn = $this->createFile([
'note' => 'NOTE UPDATED',
'new.foo' => 'newFoo',
]);
$filenameFr = $this->createFile([
], 'en');
$filenameMessagesFr = $this->createFile([
'note' => 'NOTE MISE À JOUR',
'new.foo' => 'nouveauFoo',
], 'fr');
$filenameValidatorsEn = $this->createFile([
'foo.error' => 'Wrong value',
'bar.success' => 'Form valid!',
], 'en', 'validators.%locale%.xlf');
$filenameValidatorsFr = $this->createFile([
'foo.error' => 'Valeur erronée',
'bar.success' => 'Formulaire valide !',
], 'fr', 'validators.%locale%.xlf');
$locales = ['en', 'fr'];
$domains = ['messages'];
$domains = ['messages', 'validators'];

$provider = $this->createMock(ProviderInterface::class);

$localTranslatorBag = new TranslatorBag();
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameEn, 'en'));
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameFr, 'fr'));
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameMessagesEn, 'en', 'messages'));
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameMessagesFr, 'fr', 'messages'));
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameValidatorsEn, 'en', 'validators'));
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameValidatorsFr, 'fr', 'validators'));

$provider->expects($this->once())
->method('write')
Expand All @@ -117,9 +127,9 @@ public function testPushForceMessages()

$tester = $this->createCommandTester($provider, $locales, $domains);

$tester->execute(['--locales' => ['en', 'fr'], '--domains' => ['messages'], '--force' => true]);
$tester->execute(['--locales' => $locales, '--domains' => $domains, '--force' => true]);

$this->assertStringContainsString('[OK] All local translations has been sent to "null" (for "en, fr" locale(s), and "messages" domain(s)).', trim($tester->getDisplay()));
$this->assertStringContainsString('[OK] All local translations has been sent to "null" (for "en, fr" locale(s), and "messages, validators" domain(s)).', trim($tester->getDisplay()));
}

public function testDeleteMissingMessages()
Expand Down

0 comments on commit dcc3b6e

Please sign in to comment.