Catalogue
2 months ago
Command
2 months ago
DataCollector
2 months ago
DependencyInjection
2 months ago
Dumper
2 months ago
Exception
2 months ago
Extractor
2 months ago
Formatter
2 months ago
Loader
2 months ago
Provider
2 months ago
Reader
2 months ago
Resources
2 months ago
Util
2 months ago
Writer
2 months ago
DataCollectorTranslator.php
2 months ago
IdentityTranslator.php
2 months ago
LoggingTranslator.php
2 months ago
MessageCatalogue.php
2 months ago
MessageCatalogueInterface.php
2 months ago
MetadataAwareInterface.php
2 months ago
PseudoLocalizationTranslator.php
2 months ago
TranslatableMessage.php
2 months ago
Translator.php
2 months ago
TranslatorBag.php
2 months ago
TranslatorBagInterface.php
2 months ago
TranslatorBag.php
85 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace ProfilePressVendor\Symfony\Component\Translation; |
| 12 | |
| 13 | use ProfilePressVendor\Symfony\Component\Translation\Catalogue\AbstractOperation; |
| 14 | use ProfilePressVendor\Symfony\Component\Translation\Catalogue\TargetOperation; |
| 15 | final class TranslatorBag implements TranslatorBagInterface |
| 16 | { |
| 17 | /** @var MessageCatalogue[] */ |
| 18 | private $catalogues = []; |
| 19 | public function addCatalogue(MessageCatalogue $catalogue): void |
| 20 | { |
| 21 | if (null !== $existingCatalogue = $this->getCatalogue($catalogue->getLocale())) { |
| 22 | $catalogue->addCatalogue($existingCatalogue); |
| 23 | } |
| 24 | $this->catalogues[$catalogue->getLocale()] = $catalogue; |
| 25 | } |
| 26 | public function addBag(TranslatorBagInterface $bag): void |
| 27 | { |
| 28 | foreach ($bag->getCatalogues() as $catalogue) { |
| 29 | $this->addCatalogue($catalogue); |
| 30 | } |
| 31 | } |
| 32 | /** |
| 33 | * {@inheritdoc} |
| 34 | */ |
| 35 | public function getCatalogue(?string $locale = null): MessageCatalogueInterface |
| 36 | { |
| 37 | if (null === $locale || !isset($this->catalogues[$locale])) { |
| 38 | $this->catalogues[$locale] = new MessageCatalogue($locale); |
| 39 | } |
| 40 | return $this->catalogues[$locale]; |
| 41 | } |
| 42 | /** |
| 43 | * {@inheritdoc} |
| 44 | */ |
| 45 | public function getCatalogues(): array |
| 46 | { |
| 47 | return array_values($this->catalogues); |
| 48 | } |
| 49 | public function diff(TranslatorBagInterface $diffBag): self |
| 50 | { |
| 51 | $diff = new self(); |
| 52 | foreach ($this->catalogues as $locale => $catalogue) { |
| 53 | if (null === $diffCatalogue = $diffBag->getCatalogue($locale)) { |
| 54 | $diff->addCatalogue($catalogue); |
| 55 | continue; |
| 56 | } |
| 57 | $operation = new TargetOperation($diffCatalogue, $catalogue); |
| 58 | $operation->moveMessagesToIntlDomainsIfPossible(AbstractOperation::NEW_BATCH); |
| 59 | $newCatalogue = new MessageCatalogue($locale); |
| 60 | foreach ($catalogue->getDomains() as $domain) { |
| 61 | $newCatalogue->add($operation->getNewMessages($domain), $domain); |
| 62 | } |
| 63 | $diff->addCatalogue($newCatalogue); |
| 64 | } |
| 65 | return $diff; |
| 66 | } |
| 67 | public function intersect(TranslatorBagInterface $intersectBag): self |
| 68 | { |
| 69 | $diff = new self(); |
| 70 | foreach ($this->catalogues as $locale => $catalogue) { |
| 71 | if (null === $intersectCatalogue = $intersectBag->getCatalogue($locale)) { |
| 72 | continue; |
| 73 | } |
| 74 | $operation = new TargetOperation($catalogue, $intersectCatalogue); |
| 75 | $operation->moveMessagesToIntlDomainsIfPossible(AbstractOperation::OBSOLETE_BATCH); |
| 76 | $obsoleteCatalogue = new MessageCatalogue($locale); |
| 77 | foreach ($operation->getDomains() as $domain) { |
| 78 | $obsoleteCatalogue->add(array_diff($operation->getMessages($domain), $operation->getNewMessages($domain)), $domain); |
| 79 | } |
| 80 | $diff->addCatalogue($obsoleteCatalogue); |
| 81 | } |
| 82 | return $diff; |
| 83 | } |
| 84 | } |
| 85 |