Skip to content

Commit 8a3cc18

Browse files
committed
bug #43967 [Loco] Fix Loco Provider ID and pull & push local messages reading (welcoMattic)
This PR was merged into the 5.4 branch. Discussion ---------- [Loco] Fix Loco Provider ID and pull & push local messages reading | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #42395 & #43954 | License | MIT | Doc PR | It fixes Loco push new messages and avoiding Loco auto-generation of ID for each new messages (which use dash notation instead of dot notation IIRC). And it fixes also the Translation push & pull commands when they read local messages for multiple domains. Commits ------- 51ea9c8 Fix Loco Provider
2 parents be5af2a + 51ea9c8 commit 8a3cc18

File tree

5 files changed

+84
-19
lines changed

5 files changed

+84
-19
lines changed

src/Symfony/Component/Translation/Bridge/Loco/LocoProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ private function createAssets(array $keys): array
171171
foreach ($keys as $key) {
172172
$responses[$key] = $this->client->request('POST', 'assets', [
173173
'body' => [
174+
'id' => $key,
174175
'text' => $key,
175176
'type' => 'text',
176177
'default' => 'untranslated',

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function testCompleteWriteProcess()
6363
$responses = [
6464
'createAsset1' => function (string $method, string $url, array $options = []) use ($expectedAuthHeader): ResponseInterface {
6565
$expectedBody = http_build_query([
66+
'id' => 'a',
6667
'text' => 'a',
6768
'type' => 'text',
6869
'default' => 'untranslated',
@@ -99,6 +100,7 @@ public function testCompleteWriteProcess()
99100
},
100101
'createAsset2' => function (string $method, string $url, array $options = []) use ($expectedAuthHeader): ResponseInterface {
101102
$expectedBody = http_build_query([
103+
'id' => 'post.num_comments',
102104
'text' => 'post.num_comments',
103105
'type' => 'text',
104106
'default' => 'untranslated',

src/Symfony/Component/Translation/Command/TranslationTrait.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ private function readLocalTranslations(array $locales, array $domains, array $tr
3232

3333
if ($domains) {
3434
foreach ($domains as $domain) {
35-
$catalogue = $this->filterCatalogue($catalogue, $domain);
36-
$bag->addCatalogue($catalogue);
35+
$bag->addCatalogue($this->filterCatalogue($catalogue, $domain));
3736
}
3837
} else {
3938
$bag->addCatalogue($catalogue);

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

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,30 @@ public function testPullNewXlf20Messages()
196196
public function testPullForceMessages()
197197
{
198198
$arrayLoader = new ArrayLoader();
199-
$filenameEn = $this->createFile();
200-
$filenameFr = $this->createFile(['note' => 'NOTE'], 'fr');
199+
$filenameMessagesEn = $this->createFile(['note' => 'NOTE'], 'en');
200+
$filenameMessagesFr = $this->createFile(['note' => 'NOTE'], 'fr');
201+
$filenameValidatorsEn = $this->createFile(['foo.error' => 'Wrong value'], 'en', 'validators.%locale%.xlf');
202+
$filenameValidatorsFr = $this->createFile(['foo.error' => 'Valeur erronée'], 'fr', 'validators.%locale%.xlf');
201203
$locales = ['en', 'fr'];
202-
$domains = ['messages'];
204+
$domains = ['messages', 'validators'];
203205

204206
$providerReadTranslatorBag = new TranslatorBag();
205207
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
206208
'note' => 'UPDATED NOTE',
207209
'new.foo' => 'newFoo',
208-
], 'en'));
210+
], 'en', 'messages'));
209211
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
210212
'note' => 'NOTE MISE À JOUR',
211213
'new.foo' => 'nouveauFoo',
212-
], 'fr'));
214+
], 'fr', 'messages'));
215+
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
216+
'foo.error' => 'Bad value',
217+
'bar.error' => 'Bar error',
218+
], 'en', 'validators'));
219+
$providerReadTranslatorBag->addCatalogue($arrayLoader->load([
220+
'foo.error' => 'Valeur invalide',
221+
'bar.error' => 'Bar erreur',
222+
], 'fr', 'validators'));
213223

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

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

227-
$this->assertStringContainsString('[OK] Local translations has been updated from "null" (for "en, fr" locale(s), and "messages" domain(s)).', trim($tester->getDisplay()));
237+
$this->assertStringContainsString('[OK] Local translations has been updated from "null" (for "en, fr" locale(s), and "messages, validators" domain(s)).', trim($tester->getDisplay()));
228238
$this->assertXmlStringEqualsXmlString(<<<XLIFF
229239
<?xml version="1.0"?>
230240
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
@@ -245,7 +255,7 @@ public function testPullForceMessages()
245255
</file>
246256
</xliff>
247257
XLIFF
248-
, file_get_contents($filenameEn));
258+
, file_get_contents($filenameMessagesEn));
249259
$this->assertXmlStringEqualsXmlString(<<<XLIFF
250260
<?xml version="1.0"?>
251261
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
@@ -266,7 +276,50 @@ public function testPullForceMessages()
266276
</file>
267277
</xliff>
268278
XLIFF
269-
, file_get_contents($filenameFr));
279+
, file_get_contents($filenameMessagesFr));
280+
281+
$this->assertXmlStringEqualsXmlString(<<<XLIFF
282+
<?xml version="1.0"?>
283+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
284+
<file source-language="en" target-language="en" datatype="plaintext" original="file.ext">
285+
<header>
286+
<tool tool-id="symfony" tool-name="Symfony"/>
287+
</header>
288+
<body>
289+
<trans-unit id="kA4akVr" resname="foo.error">
290+
<source>foo.error</source>
291+
<target>Bad value</target>
292+
</trans-unit>
293+
<trans-unit id="OcBtn3X" resname="bar.error">
294+
<source>bar.error</source>
295+
<target>Bar error</target>
296+
</trans-unit>
297+
</body>
298+
</file>
299+
</xliff>
300+
XLIFF
301+
, file_get_contents($filenameValidatorsEn));
302+
$this->assertXmlStringEqualsXmlString(<<<XLIFF
303+
<?xml version="1.0"?>
304+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
305+
<file source-language="en" target-language="fr" datatype="plaintext" original="file.ext">
306+
<header>
307+
<tool tool-id="symfony" tool-name="Symfony"/>
308+
</header>
309+
<body>
310+
<trans-unit id="kA4akVr" resname="foo.error">
311+
<source>foo.error</source>
312+
<target>Valeur invalide</target>
313+
</trans-unit>
314+
<trans-unit id="OcBtn3X" resname="bar.error">
315+
<source>bar.error</source>
316+
<target>Bar erreur</target>
317+
</trans-unit>
318+
</body>
319+
</file>
320+
</xliff>
321+
XLIFF
322+
, file_get_contents($filenameValidatorsFr));
270323
}
271324

272325
/**

src/Symfony/Component/Translation/Tests/Command/TranslationPushCommandTest.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,32 @@ public function testPushNewMessages()
9090
public function testPushForceMessages()
9191
{
9292
$xliffLoader = new XliffFileLoader();
93-
$filenameEn = $this->createFile([
93+
$filenameMessagesEn = $this->createFile([
9494
'note' => 'NOTE UPDATED',
9595
'new.foo' => 'newFoo',
96-
]);
97-
$filenameFr = $this->createFile([
96+
], 'en');
97+
$filenameMessagesFr = $this->createFile([
9898
'note' => 'NOTE MISE À JOUR',
9999
'new.foo' => 'nouveauFoo',
100100
], 'fr');
101+
$filenameValidatorsEn = $this->createFile([
102+
'foo.error' => 'Wrong value',
103+
'bar.success' => 'Form valid!',
104+
], 'en', 'validators.%locale%.xlf');
105+
$filenameValidatorsFr = $this->createFile([
106+
'foo.error' => 'Valeur erronée',
107+
'bar.success' => 'Formulaire valide !',
108+
], 'fr', 'validators.%locale%.xlf');
101109
$locales = ['en', 'fr'];
102-
$domains = ['messages'];
110+
$domains = ['messages', 'validators'];
103111

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

106114
$localTranslatorBag = new TranslatorBag();
107-
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameEn, 'en'));
108-
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameFr, 'fr'));
115+
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameMessagesEn, 'en', 'messages'));
116+
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameMessagesFr, 'fr', 'messages'));
117+
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameValidatorsEn, 'en', 'validators'));
118+
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameValidatorsFr, 'fr', 'validators'));
109119

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

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

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

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

125135
public function testDeleteMissingMessages()

0 commit comments

Comments
 (0)