Exemplo n.º 1
0
 /**
  * @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);
 }
Exemplo n.º 3
0
 /**
  * @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;
 }
Exemplo n.º 4
0
 /**
  * {@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);
     }
 }
Exemplo n.º 5
0
 /**
  *
  * {@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);
     }
 }
Exemplo n.º 6
0
Arquivo: Export.php Projeto: sulu/sulu
 /**
  * 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;
 }