Exception
1 year ago
Provider
1 year ago
Test
1 year ago
Util
1 year ago
DataCollectorTranslator.php
1 year ago
IdentityTranslator.php
1 year ago
LoggingTranslator.php
1 year ago
MessageCatalogue.php
1 year ago
MessageCatalogueInterface.php
1 year ago
MetadataAwareInterface.php
1 year ago
PseudoLocalizationTranslator.php
1 year ago
TranslatableMessage.php
1 year ago
Translator.php
1 year ago
TranslatorBag.php
1 year ago
TranslatorBagInterface.php
1 year ago
index.php
3 years ago
TranslatorBag.php
69 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Translation; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\Translation\Catalogue\AbstractOperation; |
| 5 | use MailPoetVendor\Symfony\Component\Translation\Catalogue\TargetOperation; |
| 6 | final class TranslatorBag implements TranslatorBagInterface |
| 7 | { |
| 8 | private $catalogues = []; |
| 9 | public function addCatalogue(MessageCatalogue $catalogue) : void |
| 10 | { |
| 11 | if (null !== ($existingCatalogue = $this->getCatalogue($catalogue->getLocale()))) { |
| 12 | $catalogue->addCatalogue($existingCatalogue); |
| 13 | } |
| 14 | $this->catalogues[$catalogue->getLocale()] = $catalogue; |
| 15 | } |
| 16 | public function addBag(TranslatorBagInterface $bag) : void |
| 17 | { |
| 18 | foreach ($bag->getCatalogues() as $catalogue) { |
| 19 | $this->addCatalogue($catalogue); |
| 20 | } |
| 21 | } |
| 22 | public function getCatalogue(?string $locale = null) : MessageCatalogueInterface |
| 23 | { |
| 24 | if (null === $locale || !isset($this->catalogues[$locale])) { |
| 25 | $this->catalogues[$locale] = new MessageCatalogue($locale); |
| 26 | } |
| 27 | return $this->catalogues[$locale]; |
| 28 | } |
| 29 | public function getCatalogues() : array |
| 30 | { |
| 31 | return \array_values($this->catalogues); |
| 32 | } |
| 33 | public function diff(TranslatorBagInterface $diffBag) : self |
| 34 | { |
| 35 | $diff = new self(); |
| 36 | foreach ($this->catalogues as $locale => $catalogue) { |
| 37 | if (null === ($diffCatalogue = $diffBag->getCatalogue($locale))) { |
| 38 | $diff->addCatalogue($catalogue); |
| 39 | continue; |
| 40 | } |
| 41 | $operation = new TargetOperation($diffCatalogue, $catalogue); |
| 42 | $operation->moveMessagesToIntlDomainsIfPossible(AbstractOperation::NEW_BATCH); |
| 43 | $newCatalogue = new MessageCatalogue($locale); |
| 44 | foreach ($catalogue->getDomains() as $domain) { |
| 45 | $newCatalogue->add($operation->getNewMessages($domain), $domain); |
| 46 | } |
| 47 | $diff->addCatalogue($newCatalogue); |
| 48 | } |
| 49 | return $diff; |
| 50 | } |
| 51 | public function intersect(TranslatorBagInterface $intersectBag) : self |
| 52 | { |
| 53 | $diff = new self(); |
| 54 | foreach ($this->catalogues as $locale => $catalogue) { |
| 55 | if (null === ($intersectCatalogue = $intersectBag->getCatalogue($locale))) { |
| 56 | continue; |
| 57 | } |
| 58 | $operation = new TargetOperation($catalogue, $intersectCatalogue); |
| 59 | $operation->moveMessagesToIntlDomainsIfPossible(AbstractOperation::OBSOLETE_BATCH); |
| 60 | $obsoleteCatalogue = new MessageCatalogue($locale); |
| 61 | foreach ($operation->getDomains() as $domain) { |
| 62 | $obsoleteCatalogue->add(\array_diff($operation->getMessages($domain), $operation->getNewMessages($domain)), $domain); |
| 63 | } |
| 64 | $diff->addCatalogue($obsoleteCatalogue); |
| 65 | } |
| 66 | return $diff; |
| 67 | } |
| 68 | } |
| 69 |