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 a0b0692

Browse filesBrowse files
committed
Fix idempotency of LocoProvider write method
1 parent 0f6b07e commit a0b0692
Copy full SHA for a0b0692

File tree

2 files changed

+20
-9
lines changed
Filter options

2 files changed

+20
-9
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Bridge/Loco/LocoProvider.php
+19-7Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,15 @@ public function write(TranslatorBagInterface $translatorBag): void
7575
}
7676

7777
foreach ($catalogue->all() as $domain => $messages) {
78-
$ids = $this->getAssetsIds($domain);
79-
$this->translateAssets(array_combine($ids, array_values($messages)), $locale);
78+
$keysIdsMap = [];
79+
80+
foreach ($this->getAssetsIds($domain) as $id) {
81+
$keysIdsMap[$this->retrieveKeyFromId($id, $domain)] = $id;
82+
}
83+
84+
$ids = array_intersect_key($keysIdsMap, $messages);
85+
86+
$this->translateAssets(array_combine(array_values($ids), array_values($messages)), $locale);
8087
}
8188
}
8289
}
@@ -122,11 +129,7 @@ public function read(array $domains, array $locales): TranslatorBag
122129
$catalogue = new MessageCatalogue($locale);
123130

124131
foreach ($locoCatalogue->all($domain) as $key => $message) {
125-
if (str_starts_with($key, $domain.'__')) {
126-
$key = substr($key, \strlen($domain) + 2);
127-
}
128-
129-
$catalogue->set($key, $message, $domain);
132+
$catalogue->set($this->retrieveKeyFromId($key, $domain), $message, $domain);
130133
}
131134

132135
$translatorBag->addCatalogue($catalogue);
@@ -289,4 +292,13 @@ private function getLocales(): array
289292
return $carry;
290293
}, []);
291294
}
295+
296+
private function retrieveKeyFromId(string $id, string $domain): string
297+
{
298+
if (str_starts_with($id, $domain.'__')) {
299+
return substr($id, \strlen($domain) + 2);
300+
}
301+
302+
return $id;
303+
}
292304
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/Command/TranslationPushCommandTest.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
12+
namespace Symfony\Component\Translation\Tests\Command;
1313

1414
use Symfony\Component\Console\Application;
1515
use Symfony\Component\Console\Tester\CommandTester;
@@ -18,7 +18,6 @@
1818
use Symfony\Component\Translation\Loader\XliffFileLoader;
1919
use Symfony\Component\Translation\Provider\ProviderInterface;
2020
use Symfony\Component\Translation\Reader\TranslationReader;
21-
use Symfony\Component\Translation\Tests\Command\TranslationProviderTestCase;
2221
use Symfony\Component\Translation\TranslatorBag;
2322

2423
/**

0 commit comments

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