Skip to content

[Translation] TranslatorBag::diff now iterates over catalogue domains instead of operation domains #49833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,52 @@ public function testPushNewMessages()
$this->assertStringContainsString('[OK] New local translations has been sent to "null" (for "en, fr" locale(s), and "messages" domain(s)).', trim($tester->getDisplay()));
}

public function testPushNewIntlIcuMessages()
{
$arrayLoader = new ArrayLoader();
$xliffLoader = new XliffFileLoader();
$locales = ['en', 'fr'];
$domains = ['messages'];

// Simulate existing messages on Provider
$providerReadTranslatorBag = new TranslatorBag();
$providerReadTranslatorBag->addCatalogue($arrayLoader->load(['note' => 'NOTE'], 'en'));
$providerReadTranslatorBag->addCatalogue($arrayLoader->load(['note' => 'NOTE'], 'fr'));

$provider = $this->createMock(ProviderInterface::class);
$provider->expects($this->once())
->method('read')
->with($domains, $locales)
->willReturn($providerReadTranslatorBag);

// Create local files, with a new message
$filenameEn = $this->createFile([
'note' => 'NOTE',
'new.foo' => 'newFooIntlIcu',
], 'en', 'messages+intl-icu.%locale%.xlf');
$filenameFr = $this->createFile([
'note' => 'NOTE',
'new.foo' => 'nouveauFooIntlIcu',
], 'fr', 'messages+intl-icu.%locale%.xlf');
$localTranslatorBag = new TranslatorBag();
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameEn, 'en'));
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameFr, 'fr'));

$provider->expects($this->once())
->method('write')
->with($localTranslatorBag->diff($providerReadTranslatorBag));

$provider->expects($this->once())
->method('__toString')
->willReturn('null://default');

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

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

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

public function testPushForceMessages()
{
$xliffLoader = new XliffFileLoader();
Expand Down
28 changes: 28 additions & 0 deletions src/Symfony/Component/Translation/Tests/TranslatorBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,34 @@ public function testDiff()
], $this->getAllMessagesFromTranslatorBag($bagResult));
}

public function testDiffWithIntlDomain()
{
$catalogueA = new MessageCatalogue('en', [
'domain1+intl-icu' => ['foo' => 'foo', 'bar' => 'bar'],
'domain2' => ['baz' => 'baz', 'qux' => 'qux'],
]);

$bagA = new TranslatorBag();
$bagA->addCatalogue($catalogueA);

$catalogueB = new MessageCatalogue('en', [
'domain1' => ['foo' => 'foo'],
'domain2' => ['baz' => 'baz', 'corge' => 'corge'],
]);

$bagB = new TranslatorBag();
$bagB->addCatalogue($catalogueB);

$bagResult = $bagA->diff($bagB);

$this->assertEquals([
'en' => [
'domain1' => ['bar' => 'bar'],
'domain2' => ['qux' => 'qux'],
],
], $this->getAllMessagesFromTranslatorBag($bagResult));
}

public function testIntersect()
{
$catalogueA = new MessageCatalogue('en', ['domain1' => ['foo' => 'foo', 'bar' => 'bar'], 'domain2' => ['baz' => 'baz', 'qux' => 'qux']]);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/TranslatorBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function diff(TranslatorBagInterface $diffBag): self
$operation->moveMessagesToIntlDomainsIfPossible(AbstractOperation::NEW_BATCH);
$newCatalogue = new MessageCatalogue($locale);

foreach ($operation->getDomains() as $domain) {
foreach ($catalogue->getDomains() as $domain) {
$newCatalogue->add($operation->getNewMessages($domain), $domain);
}

Expand Down
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