|
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 |
|
@@ -216,6 +217,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int
|
216 | 217 |
|
217 | 218 | $resultMessage = 'Translation files were successfully updated';
|
218 | 219 |
|
| 220 | + // move new messages to intl domain when possible |
| 221 | + if (class_exists(\MessageFormatter::class)) { |
| 222 | + foreach ($operation->getDomains() as $domain) { |
| 223 | + $intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX; |
| 224 | + $newMessages = $operation->getNewMessages($domain); |
| 225 | + |
| 226 | + if ([] === $newMessages || ([] === $currentCatalogue->all($intlDomain) && [] !== $currentCatalogue->all($domain))) { |
| 227 | + continue; |
| 228 | + } |
| 229 | + |
| 230 | + $result = $operation->getResult(); |
| 231 | + $allIntlMessages = $result->all($intlDomain); |
| 232 | + $currentMessages = array_diff_key($newMessages, $result->all($domain)); |
| 233 | + $result->replace($currentMessages, $domain); |
| 234 | + $result->replace($allIntlMessages + $newMessages, $intlDomain); |
| 235 | + } |
| 236 | + } |
| 237 | + |
219 | 238 | // show compiled list of messages
|
220 | 239 | if (true === $input->getOption('dump-messages')) {
|
221 | 240 | $extractedMessagesCount = 0;
|
|
0 commit comments