Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1802488

Browse filesBrowse files
Kocalnicolas-grekas
authored andcommitted
[Translation] Fix TranslationPullCommand with ICU translations
1 parent a7e4494 commit 1802488
Copy full SHA for 1802488

File tree

Expand file treeCollapse file tree

5 files changed

+93
-9
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+93
-9
lines changed

‎src/Symfony/Component/Translation/Bridge/Loco/Tests/LocoProviderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Bridge/Loco/Tests/LocoProviderTest.php
+33-3Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,16 @@ public function getResponsesForManyLocalesAndManyDomains(): \Generator
426426
$expectedTranslatorBag = new TranslatorBag();
427427
$expectedTranslatorBag->addCatalogue($arrayLoader->load([
428428
'index.hello' => 'Hello',
429-
'index.greetings' => 'Welcome, {firstname}!',
430429
], 'en'));
430+
$expectedTranslatorBag->addCatalogue($arrayLoader->load([
431+
'index.greetings' => 'Welcome, {firstname}!',
432+
], 'en', 'messages+intl-icu'));
431433
$expectedTranslatorBag->addCatalogue($arrayLoader->load([
432434
'index.hello' => 'Bonjour',
433-
'index.greetings' => 'Bienvenue, {firstname} !',
434435
], 'fr'));
436+
$expectedTranslatorBag->addCatalogue($arrayLoader->load([
437+
'index.greetings' => 'Bienvenue, {firstname} !',
438+
], 'fr', 'messages+intl-icu'));
435439
$expectedTranslatorBag->addCatalogue($arrayLoader->load([
436440
'firstname.error' => 'Firstname must contains only letters.',
437441
'lastname.error' => 'Lastname must contains only letters.',
@@ -443,7 +447,7 @@ public function getResponsesForManyLocalesAndManyDomains(): \Generator
443447

444448
yield [
445449
['en', 'fr'],
446-
['messages', 'validators'],
450+
['messages', 'messages+intl-icu', 'validators'],
447451
[
448452
'en' => [
449453
'messages' => <<<'XLIFF'
@@ -458,6 +462,19 @@ public function getResponsesForManyLocalesAndManyDomains(): \Generator
458462
<source>index.hello</source>
459463
<target state="translated">Hello</target>
460464
</trans-unit>
465+
</body>
466+
</file>
467+
</xliff>
468+
XLIFF
469+
,
470+
'messages+intl-icu' => <<<'XLIFF'
471+
<?xml version="1.0" encoding="UTF-8"?>
472+
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd">
473+
<file original="https://localise.biz/user/symfony-translation-provider" source-language="en" datatype="database" tool-id="loco">
474+
<header>
475+
<tool tool-id="loco" tool-name="Loco" tool-version="1.0.25 20201211-1" tool-company="Loco"/>
476+
</header>
477+
<body>
461478
<trans-unit id="loco:5fd89b8542e5aa5cc27457e2" resname="index.greetings" datatype="plaintext" extradata="loco:format=icu">
462479
<source>index.greetings</source>
463480
<target state="translated">Welcome, {firstname}!</target>
@@ -502,6 +519,19 @@ public function getResponsesForManyLocalesAndManyDomains(): \Generator
502519
<source>index.hello</source>
503520
<target state="translated">Bonjour</target>
504521
</trans-unit>
522+
</body>
523+
</file>
524+
</xliff>
525+
XLIFF
526+
,
527+
'messages+intl-icu' => <<<'XLIFF'
528+
<?xml version="1.0" encoding="UTF-8"?>
529+
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd">
530+
<file original="https://localise.biz/user/symfony-translation-provider" source-language="en" datatype="database" tool-id="loco">
531+
<header>
532+
<tool tool-id="loco" tool-name="Loco" tool-version="1.0.25 20201211-1" tool-company="Loco"/>
533+
</header>
534+
<body>
505535
<trans-unit id="loco:5fd89b8542e5aa5cc27457e2" resname="index.greetings" datatype="plaintext" extradata="loco:format=icu">
506536
<source>index.greetings</source>
507537
<target state="translated">Bienvenue, {firstname} !</target>

‎src/Symfony/Component/Translation/Catalogue/AbstractOperation.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Catalogue/AbstractOperation.php
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,18 @@ public function __construct(MessageCatalogueInterface $source, MessageCatalogueI
8383
public function getDomains()
8484
{
8585
if (null === $this->domains) {
86-
$this->domains = array_values(array_unique(array_merge($this->source->getDomains(), $this->target->getDomains())));
86+
$domains = [];
87+
foreach ([$this->source, $this->target] as $catalogue) {
88+
foreach ($catalogue->getDomains() as $domain) {
89+
$domains[$domain] = $domain;
90+
91+
if ($catalogue->all($domainIcu = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX)) {
92+
$domains[$domainIcu] = $domainIcu;
93+
}
94+
}
95+
}
96+
97+
$this->domains = array_values($domains);
8798
}
8899

89100
return $this->domains;

‎src/Symfony/Component/Translation/Tests/Catalogue/MergeOperationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/Catalogue/MergeOperationTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testGetResultFromIntlDomain()
5858
$this->assertEquals(
5959
new MessageCatalogue('en', [
6060
'messages' => ['a' => 'old_a', 'b' => 'old_b'],
61-
'messages+intl-icu' => ['d' => 'old_d', 'c' => 'new_c'],
61+
'messages+intl-icu' => ['d' => 'old_d', 'c' => 'new_c', 'a' => 'new_a'],
6262
]),
6363
$this->createOperation(
6464
new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b'], 'messages+intl-icu' => ['d' => 'old_d']]),

‎src/Symfony/Component/Translation/Tests/Catalogue/TargetOperationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/Catalogue/TargetOperationTest.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function testGetResultWithMixedDomains()
7272
$this->assertEquals(
7373
new MessageCatalogue('en', [
7474
'messages' => ['a' => 'old_a'],
75+
'messages+intl-icu' => ['a' => 'new_a'],
7576
]),
7677
$this->createOperation(
7778
new MessageCatalogue('en', ['messages' => ['a' => 'old_a']]),
@@ -103,7 +104,7 @@ public function testGetResultWithMixedDomains()
103104
$this->assertEquals(
104105
new MessageCatalogue('en', [
105106
'messages' => ['a' => 'old_a'],
106-
'messages+intl-icu' => ['b' => 'new_b'],
107+
'messages+intl-icu' => ['b' => 'new_b', 'a' => 'new_a'],
107108
]),
108109
$this->createOperation(
109110
new MessageCatalogue('en', ['messages' => ['a' => 'old_a']]),

‎src/Symfony/Component/Translation/Tests/Command/TranslationPullCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/Command/TranslationPullCommandTest.php
+45-3Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,27 @@ public function testPullNewXlf12Messages()
4646
{
4747
$arrayLoader = new ArrayLoader();
4848
$filenameEn = $this->createFile();
49+
$filenameEnIcu = $this->createFile(['say_hello' => 'Welcome, {firstname}!'], 'en', 'messages+intl-icu.%locale%.xlf');
4950
$filenameFr = $this->createFile(['note' => 'NOTE'], 'fr');
51+
$filenameFrIcu = $this->createFile(['say_hello' => 'Bonjour, {firstname}!'], 'fr', 'messages+intl-icu.%locale%.xlf');
5052
$locales = ['en', 'fr'];
51-
$domains = ['messages'];
53+
$domains = ['messages', 'messages+intl-icu'];
5254

5355
$providerReadTranslatorBag = new TranslatorBag();
5456
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
5557
'note' => 'NOTE',
5658
'new.foo' => 'newFoo',
5759
], 'en'));
60+
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
61+
'say_hello' => 'Welcome, {firstname}!',
62+
], 'en', 'messages+intl-icu'));
5863
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
5964
'note' => 'NOTE',
6065
'new.foo' => 'nouveauFoo',
6166
], 'fr'));
67+
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
68+
'say_hello' => 'Bonjour, {firstname}!',
69+
], 'fr', 'messages+intl-icu'));
6270

6371
$provider = $this->createMock(ProviderInterface::class);
6472
$provider->expects($this->once())
@@ -71,9 +79,9 @@ public function testPullNewXlf12Messages()
7179
->willReturn('null://default');
7280

7381
$tester = $this->createCommandTester($provider, $locales, $domains);
74-
$tester->execute(['--locales' => ['en', 'fr'], '--domains' => ['messages']]);
82+
$tester->execute(['--locales' => ['en', 'fr'], '--domains' => ['messages', 'messages+intl-icu']]);
7583

76-
$this->assertStringContainsString('[OK] New translations from "null" has been written locally (for "en, fr" locale(s), and "messages" domain(s)).', trim($tester->getDisplay()));
84+
$this->assertStringContainsString('[OK] New translations from "null" has been written locally (for "en, fr" locale(s), and "messages, messages+intl-icu"', trim($tester->getDisplay()));
7785
$this->assertXmlStringEqualsXmlString(<<<XLIFF
7886
<?xml version="1.0"?>
7987
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
@@ -97,6 +105,23 @@ public function testPullNewXlf12Messages()
97105
, file_get_contents($filenameEn));
98106
$this->assertXmlStringEqualsXmlString(<<<XLIFF
99107
<?xml version="1.0"?>
108+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
109+
<file source-language="en" target-language="en" datatype="plaintext" original="file.ext">
110+
<header>
111+
<tool tool-id="symfony" tool-name="Symfony"/>
112+
</header>
113+
<body>
114+
<trans-unit id="1IHotcu" resname="say_hello">
115+
<source>say_hello</source>
116+
<target>Welcome, {firstname}!</target>
117+
</trans-unit>
118+
</body>
119+
</file>
120+
</xliff>
121+
XLIFF
122+
, file_get_contents($filenameEnIcu));
123+
$this->assertXmlStringEqualsXmlString(<<<XLIFF
124+
<?xml version="1.0"?>
100125
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
101126
<file source-language="en" target-language="fr" datatype="plaintext" original="file.ext">
102127
<header>
@@ -116,6 +141,23 @@ public function testPullNewXlf12Messages()
116141
</xliff>
117142
XLIFF
118143
, file_get_contents($filenameFr));
144+
$this->assertXmlStringEqualsXmlString(<<<XLIFF
145+
<?xml version="1.0"?>
146+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
147+
<file source-language="en" target-language="fr" datatype="plaintext" original="file.ext">
148+
<header>
149+
<tool tool-id="symfony" tool-name="Symfony"/>
150+
</header>
151+
<body>
152+
<trans-unit id="1IHotcu" resname="say_hello">
153+
<source>say_hello</source>
154+
<target>Bonjour, {firstname}!</target>
155+
</trans-unit>
156+
</body>
157+
</file>
158+
</xliff>
159+
XLIFF
160+
, file_get_contents($filenameFrIcu));
119161
}
120162

121163
public function testPullNewXlf20Messages()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.