|
23 | 23 | use Symfony\Component\Translation\Catalogue\TargetOperation;
|
24 | 24 | use Symfony\Component\Translation\Extractor\ExtractorInterface;
|
25 | 25 | use Symfony\Component\Translation\MessageCatalogue;
|
| 26 | +use Symfony\Component\Translation\MessageCatalogueInterface; |
26 | 27 | use Symfony\Component\Translation\Reader\TranslationReaderInterface;
|
27 | 28 | use Symfony\Component\Translation\Writer\TranslationWriterInterface;
|
28 | 29 |
|
@@ -254,6 +255,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int
|
254 | 255 |
|
255 | 256 | $resultMessage = 'Translation files were successfully updated';
|
256 | 257 |
|
| 258 | + // move new messages to intl domain when possible |
| 259 | + if (class_exists(\MessageFormatter::class)) { |
| 260 | + foreach ($operation->getDomains() as $domain) { |
| 261 | + $intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX; |
| 262 | + $newMessages = $operation->getNewMessages($domain); |
| 263 | + |
| 264 | + if ([] === $newMessages || ([] === $currentCatalogue->all($intlDomain) && [] !== $currentCatalogue->all($domain))) { |
| 265 | + continue; |
| 266 | + } |
| 267 | + |
| 268 | + $result = $operation->getResult(); |
| 269 | + $allIntlMessages = $result->all($intlDomain); |
| 270 | + $currentMessages = array_diff_key($newMessages, $result->all($domain)); |
| 271 | + $result->replace($currentMessages, $domain); |
| 272 | + $result->replace($allIntlMessages + $newMessages, $intlDomain); |
| 273 | + } |
| 274 | + } |
| 275 | + |
257 | 276 | // show compiled list of messages
|
258 | 277 | if (true === $input->getOption('dump-messages')) {
|
259 | 278 | $extractedMessagesCount = 0;
|
|
0 commit comments