Skip to content
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

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

Merged
merged 1 commit into from
Mar 30, 2023

Conversation

welcoMattic
Copy link
Member

@welcoMattic welcoMattic commented Mar 27, 2023

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #47886
License MIT
Doc PR

For Loco Provider (at least, but I'm pretty sure it applies for Lokalise and Crowdin), the --force option on translation:push command has no effect.

The main cause is located in the TranslatorBag::diff method which was iterating over $operation->getDomains() to add new messages to the diff catalogue. But, the fact is $operation->getDomains() returns all domains AND their +intl-icu variants! Which is certainly not what we want here.

See the test that covers the case

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));
}

Without the change, 'foo' => 'foo' was in the result bag.

Replaces #47986

@fabpot
Copy link
Member

fabpot commented Mar 30, 2023

Thank you @welcoMattic.

@fabpot fabpot merged commit 96b9f0f into symfony:5.4 Mar 30, 2023
@welcoMattic welcoMattic deleted the fix-translatorbag-diff branch March 30, 2023 08:50
This was referenced Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants