protected function execute(InputInterface $input, OutputInterface $output)
 {
     $masterLanguage = $input->getArgument('master');
     $slaveLanguage = $input->getArgument('slave');
     $masterLanguageFile = $this->path . 'messages.' . $masterLanguage . '.yml';
     $slaveLanguageFile = $this->path . 'messages.' . $slaveLanguage . '.yml';
     $catMasterFile = $this->loader->load($masterLanguageFile, $masterLanguage);
     $catSlaveFile = $this->loader->load($slaveLanguageFile, $slaveLanguage);
     foreach ($catMasterFile->all('messages') as $key => $value) {
         if (!$catSlaveFile->has($key)) {
             $catSlaveFile->set($key, "TODO: {$value}");
         }
     }
     $messages = $catMasterFile->all('messages');
     ksort($messages);
     $catSlaveFile->replace($messages);
     foreach ($messages as $key => $value) {
         $catSlaveFile->set($key, $value);
     }
     $output->writeln('Slave file can modify');
     $dumper = new YamlFileDumper();
     $dumper->dump($catSlaveFile, array('path' => $this->path));
     /*unlink created trash file*/
     if (file_exists($slaveLanguageFile . '~')) {
         unlink($slaveLanguageFile . '~');
     }
     $output->writeln($slaveLanguageFile . ' --> <info>Slave file updated</info>');
 }
Exemplo n.º 2
0
 function it_adds_theme_name_to_keys_if_given_file_is_included_in_theme(LoaderInterface $loader, ThemeRepositoryInterface $themeRepository, MessageCatalogueInterface $messageCatalogue, ThemeInterface $theme)
 {
     $loader->load('/theme/resource.en.xml', 'en', 'messages')->willReturn($messageCatalogue);
     $themeRepository->findOneByPath('/theme/resource.en.xml')->willReturn($theme);
     $theme->getName()->willReturn('sylius/sample-theme');
     $messageCatalogue->all('messages')->willReturn(['key' => 'value']);
     $messageCatalogue->replace(['key|sylius/sample-theme' => 'value'], 'messages')->shouldBeCalled();
     $this->load('/theme/resource.en.xml', 'en', 'messages')->shouldReturn($messageCatalogue);
 }
Exemplo n.º 3
0
 function it_adds_theme_logical_name_to_keys_if_given_file_is_included_in_theme(LoaderInterface $loader, MessageCatalogueInterface $messageCatalogue)
 {
     $loader->load($this->getThemeTranslationResourcePath(), 'en', 'messages')->shouldBeCalled()->willReturn($messageCatalogue);
     $messagesBefore = ["key" => "value"];
     $messagesAfter = ["key|sylius/sample-theme" => "value"];
     $messageCatalogue->all('messages')->shouldBeCalled()->willReturn($messagesBefore);
     $messageCatalogue->replace($messagesAfter, 'messages')->shouldBeCalled();
     $this->load($this->getThemeTranslationResourcePath(), 'en', 'messages')->shouldReturn($messageCatalogue);
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $messageCatalogue = $this->loader->load($resource, $locale, $domain);
     if (null !== ($theme = $this->resourcesToThemes->get(realpath($resource)))) {
         $messages = $messageCatalogue->all($domain);
         foreach ($messages as $key => $value) {
             unset($messages[$key]);
             $messages[$key . '|' . $theme->getLogicalName()] = $value;
         }
         $messageCatalogue->replace($messages, $domain);
     }
     return $messageCatalogue;
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $messageCatalogue = $this->loader->load($resource, $locale, $domain);
     $theme = $this->themeRepository->findOneByPath($resource);
     if (null !== $theme) {
         $messages = $messageCatalogue->all($domain);
         foreach ($messages as $key => $value) {
             unset($messages[$key]);
             $messages[$key . '|' . $theme->getSlug()] = $value;
         }
         $messageCatalogue->replace($messages, $domain);
     }
     return $messageCatalogue;
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $resourceKey = $this->getResourceKey($resource);
     if (null === $resourceKey) {
         return $this->innerLoader->load($resource, $locale, $domain);
     }
     $cacheKey = sprintf('%s_%s_%s', $locale, $domain, $resourceKey);
     $catalogue = $this->cache->fetch($cacheKey);
     if (false !== $catalogue) {
         return $catalogue;
     }
     $catalogue = $this->innerLoader->load($resource, $locale, $domain);
     $this->cache->save($cacheKey, $catalogue);
     return $catalogue;
 }
 /**
  * It returns all structures that are available.
  */
 public function testGetStructures()
 {
     $this->loader->load($this->mappingFile, 'page')->willReturn($this->structure->reveal());
     $this->loader->load($this->mappingFile, 'page')->shouldBeCalledTimes(1);
     $structures = $this->factory->getStructures('page');
     $this->assertEquals($this->structure->reveal(), $structures[0]);
 }
Exemplo n.º 8
0
 /**
  * It returns all structures that are available.
  */
 public function testGetStructures()
 {
     $this->loader->load($this->somethingMappingFile, 'page')->willReturn($this->somethingStructure->reveal());
     $this->loader->load($this->defaultMappingFile, 'page')->willReturn($this->defaultStructure->reveal());
     $this->loader->load($this->somethingMappingFile, 'page')->shouldBeCalledTimes(1);
     $this->loader->load($this->defaultMappingFile, 'page')->shouldBeCalledTimes(1);
     $structures = $this->factory->getStructures('page');
     $this->assertCount(3, $structures);
     $this->assertEquals($this->defaultStructure->reveal(), $structures[0]);
     $this->assertEquals($this->somethingStructure->reveal(), $structures[1]);
     $this->assertEquals($this->defaultStructure->reveal(), $structures[2]);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $masterLanguage = $input->getArgument('master');
     $slaveLanguage = $input->getArgument('slave');
     $fileName = $input->getOption('file-name');
     $masterLanguageFile = $this->path . $fileName . '.' . $masterLanguage . '.yml';
     $slaveLanguageFile = $this->path . $fileName . '.' . $slaveLanguage . '.yml';
     if (!file_exists($slaveLanguageFile)) {
         $touch = touch($slaveLanguageFile);
         if ($touch) {
             $output->writeln($slaveLanguageFile . ' --> <info>Slave file created</info>');
         } else {
             $output->writeln($slaveLanguageFile . ' --> <fg=black;bg=red>Slave file can not created<fg=black;bg=red>');
         }
     }
     $catMasterFile = $this->loader->load($masterLanguageFile, $masterLanguage, $fileName);
     $catSlaveFile = $this->loader->load($slaveLanguageFile, $slaveLanguage, $fileName);
     foreach ($catMasterFile->all($fileName) as $key => $value) {
         if (!$catSlaveFile->has($key, $fileName)) {
             $catSlaveFile->set($key, "TODO: " . $value, $fileName);
         }
     }
     $messages = $catSlaveFile->all($fileName);
     ksort($messages);
     $catSlaveFile->replace($messages, $fileName);
     foreach ($messages as $key => $value) {
         $catSlaveFile->set($key, $value, $fileName);
     }
     $output->writeln('Slave file can modify');
     $dumper = new YamlFileDumper();
     $dumper->dump($catSlaveFile, array('path' => $this->path));
     /*unlink created trash file*/
     if (file_exists($slaveLanguageFile . '~')) {
         unlink($slaveLanguageFile . '~');
     }
     $output->writeln($slaveLanguageFile . ' --> <info>Slave file updated</info>');
 }
Exemplo n.º 10
0
 /**
  * Load domain data from file.
  *
  * @param string          $locale
  * @param string          $domain
  * @param SplFileInfo     $file
  * @param LoaderInterface $loader
  * @return MessageCatalogue
  */
 protected function loadCatalogue($locale, $domain, SplFileInfo $file, LoaderInterface $loader)
 {
     return $loader->load((string) $file, $locale, $domain);
 }
Exemplo n.º 11
0
 /**
  * Imports a single file.
  *
  * @param Package         $package  the package to import the file into
  * @param LoaderInterface $loader
  * @param string          $path     The path to the file
  * @param string          $filename The filename
  * @param bool            $backend  True to make the file available in the backend
  * @param bool            $frontend True to make the file available in the frontend
  * @param bool            $throw    If true the methods throws exception if the a file cannot be found
  *
  * @throws \Exception
  * @throws \InvalidArgumentException
  * @throws \Symfony\Component\Translation\Exception\NotFoundResourceException
  */
 private function importFile($package, $loader, $path, $filename, $backend = true, $frontend = false, $throw = false)
 {
     try {
         $this->output->writeln($filename);
         $filePath = $path ? $path . '/' . $filename : $filename;
         $file = $loader->load($filePath, $this->locale);
         // find the catalogue from this package matching the given locale
         $catalogue = null;
         $newCatalogue = true;
         foreach ($package->getCatalogues() as $packageCatalogue) {
             /** @var $packageCatalogue Catalogue */
             if ($packageCatalogue->getLocale() === $this->locale) {
                 $catalogue = $packageCatalogue;
                 $newCatalogue = false;
             }
         }
         // if no catalogue is found create a new one
         if ($newCatalogue === true) {
             $catalogue = new Catalogue();
             if ($this->locale === $this->defaultLocale) {
                 $catalogue->setIsDefault(true);
             } else {
                 $catalogue->setIsDefault(false);
             }
             $catalogue->setPackage($package);
             $package->addCatalogue($catalogue);
             $catalogue->setLocale($this->locale);
             $this->em->persist($catalogue);
             $this->em->flush();
         }
         $allMessages = $file->all()['messages'];
         $progress = new ProgressHelper();
         $progress->start($this->output, count($allMessages));
         // loop through all translation units in the file
         foreach ($allMessages as $key => $message) {
             // Check if code is already existing in current catalogue
             if (!$newCatalogue && ($translate = $catalogue->findTranslation($key))) {
                 // Update the old translate
                 $translate->setValue($message);
             } else {
                 // Create new code, if not already existing
                 $code = $package->findCode($key);
                 if (!$code) {
                     $code = new Code();
                     $code->setPackage($package);
                     $code->setCode($key);
                     $code->setBackend($backend);
                     $code->setFrontend($frontend);
                     $this->em->persist($code);
                     $this->em->flush();
                 }
                 // Create new translate
                 $translate = new Translation();
                 $translate->setCode($code);
                 $translate->setValue($message);
                 $translate->setCatalogue($catalogue);
                 $this->em->persist($translate);
             }
             $progress->advance();
         }
         $this->em->flush();
         $progress->finish();
     } catch (\InvalidArgumentException $e) {
         if ($e instanceof NotFoundResourceException) {
             if ($throw === true) {
                 throw $e;
             }
         } else {
             throw $e;
         }
     }
 }