/** * @param MessageCatalogueInterface $catalogue */ private function parseCatalogue(MessageCatalogueInterface $catalogue) { foreach ($catalogue->all() as $domain => $messages) { foreach ($messages as $id => $translation) { if (preg_match(self::REFERENCE_REGEX, $translation, $matches)) { $catalogue->set($id, $this->getTranslation($catalogue, $id, $domain), $domain); } } } }
function let(Translator $translator, MessageCatalogueInterface $messageCatalogueAll, MessageCatalogueInterface $messageCatalogueFR, MessageCatalogueInterface $messageCatalogueEN, MessageCatalogueInterface $messageCatalogueDE) { $this->beConstructedWith($translator, 0.7); $translator->getFallbackLocales()->willReturn(['en_US']); $translator->getCatalogue(Argument::any())->willReturn($messageCatalogueAll); $messageCatalogueAll->all()->willReturn([]); $messageCatalogueEN->all()->willReturn(['scope1' => ['k1' => 't1', 'k2' => 't2', 'k3' => 't3'], 'scope2' => ['k3' => 't3']]); $translator->getCatalogue('en')->willReturn($messageCatalogueEN); $messageCatalogueFR->all()->willReturn(['scope1' => ['k1' => 't1', 'k2' => 't2'], 'scope2' => ['k3' => 't3']]); $translator->getCatalogue('fr')->willReturn($messageCatalogueFR); $messageCatalogueDE->all()->willReturn(['scope1' => ['k1' => 't1'], 'scope2' => ['k3' => 'k3']]); $translator->getCatalogue('de')->willReturn($messageCatalogueDE); }
/** * @param string $bundle * @param string $path * @param MessageCatalogueInterface $catalogue * @return $this */ public function addCatalogue($bundle, $path, MessageCatalogueInterface $catalogue) { $locale = $catalogue->getLocale(); $domains = $catalogue->getDomains(); foreach ($domains as $domain) { $messages = $catalogue->all($domain); foreach ($messages as $key => $translation) { $this->addTranslation($bundle, $domain, $locale, $key, $translation); } } /** @var ResourceInterface $resource */ foreach ($catalogue->getResources() as $resource) { $fileName = basename($resource->getResource()); $this->addFile($bundle, $path, $fileName); } return $this; }
/** * {@inheritdoc} */ public function addFallbackCatalogue(MessageCatalogueInterface $catalogue) { foreach ($catalogue->getDomains() as $domain) { foreach ($catalogue->all($domain) as $id => $translation) { if (false === $this->has($id, $domain)) { $this->set($id, $translation, $domain); } } } foreach ($catalogue->getResources() as $resource) { $this->addResource($resource); } }
/** * * {@inheritdoc} @api */ public function addCatalogue(MessageCatalogueInterface $catalogue) { if ($catalogue->getLocale() !== $this->locale) { throw new \LogicException(sprintf('Cannot add a catalogue for locale "%s" as the current locale for this catalogue is "%s"', $catalogue->getLocale(), $this->locale)); } foreach ($catalogue->all() as $domain => $messages) { $this->add($messages, $domain); } foreach ($catalogue->getResources() as $resource) { $this->addResource($resource); } if ($catalogue instanceof MetadataAwareInterface) { $metadata = $catalogue->getMetadata('', ''); $this->addMetadata($metadata); } }
/** * Gets the messages of a given catalogue and a given domain. * * @param MessageCatalogueInterface $catalogue The catalogue * @param $domain string The domain * * @return array The messages within the catalogue and the domain */ private function getMessagesForDomain(MessageCatalogueInterface $catalogue, $domain) { $messages = $catalogue->all($domain); while ($catalogue = $catalogue->getFallbackCatalogue()) { $messages = array_replace_recursive($catalogue->all($domain), $messages); } return $messages; }