/**
  *
  * {@inheritdoc}
  *
  */
 public function getDomains()
 {
     if (null === $this->domains) {
         $this->domains = array_values(array_unique(array_merge($this->source->getDomains(), $this->target->getDomains())));
     }
     return $this->domains;
 }
Example #2
0
 private function getTranslation(MessageCatalogueInterface $messages, $id, $domain)
 {
     $translation = $messages->get($id, $domain);
     if (preg_match('/^=>\\s*([a-z0-9_\\.]+)$/i', $translation, $matches)) {
         return $this->getTranslation($messages, $matches[1], $domain);
     }
     return $translation;
 }
Example #3
0
 /**
  * @param MessageCatalogueInterface $catalogue
  * @param string $id
  * @param string $domain
  * @return string
  */
 private function getTranslation(MessageCatalogueInterface $catalogue, $id, $domain)
 {
     $translation = $catalogue->get($id, $domain);
     if (preg_match(self::REFERENCE_REGEX, $translation, $matches)) {
         return $this->getTranslation($catalogue, $matches[1], $domain);
     }
     return $translation;
 }
 /**
  * @param MessageCatalogueInterface $source The source catalogue
  * @param MessageCatalogueInterface $target The target catalogue
  *
  * @throws \LogicException
  */
 public function __construct(MessageCatalogueInterface $source, MessageCatalogueInterface $target)
 {
     if ($source->getLocale() !== $target->getLocale()) {
         throw new \LogicException('Operated catalogues must belong to the same locale.');
     }
     $this->source = $source;
     $this->target = $target;
     $this->result = new MessageCatalogue($source->getLocale());
     $this->domains = null;
     $this->messages = array();
 }
 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;
 }
Example #7
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);
     }
 }
 /**
  *
  * {@inheritdoc} @api
  */
 public function addFallbackCatalogue(MessageCatalogueInterface $catalogue)
 {
     // detect circular references
     $c = $catalogue;
     while ($c = $c->getFallbackCatalogue()) {
         if ($c->getLocale() === $this->getLocale()) {
             throw new \LogicException(sprintf('Circular reference detected when adding a fallback catalogue for locale "%s".', $catalogue->getLocale()));
         }
     }
     $c = $this;
     do {
         if ($c->getLocale() === $catalogue->getLocale()) {
             throw new \LogicException(sprintf('Circular reference detected when adding a fallback catalogue for locale "%s".', $catalogue->getLocale()));
         }
     } while ($c = $c->parent);
     $catalogue->parent = $this;
     $this->fallbackCatalogue = $catalogue;
     foreach ($catalogue->getResources() as $resource) {
         $this->addResource($resource);
     }
 }
Example #9
0
File: Export.php Project: 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;
 }
 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function addFallbackCatalogue(MessageCatalogueInterface $catalogue)
 {
     $this->fallbackCatalogue = $catalogue;
     foreach ($catalogue->getResources() as $resource) {
         $this->addResource($resource);
     }
 }
Example #11
0
 /**
  * {@inheritdoc}
  */
 public function addCatalogue(MessageCatalogueInterface $catalogue)
 {
     foreach ($catalogue->getMessages() as $domain => $messages) {
         $this->addMessages($messages, $domain);
     }
     foreach ($catalogue->getResources() as $resource) {
         $this->addResource($resource);
     }
 }