예제 #1
0
 /**
  * @param Config $config
  */
 private function setConfig(Config $config)
 {
     $this->config = $config;
     $this->logger->info(sprintf("Loading catalogues from \"%s\"", $config->getTranslationsDir()));
     $this->existingCatalogue = new MessageCatalogue();
     // load external resources, so current translations can be reused in the final translation
     foreach ($config->getLoadResources() as $resource) {
         $this->existingCatalogue->merge($this->loader->loadFromDirectory($resource, $config->getLocale()));
     }
     $this->existingCatalogue->merge($this->loader->loadFromDirectory($config->getTranslationsDir(), $config->getLocale()));
     $this->extractor->reset();
     $this->extractor->setDirectories($config->getScanDirs());
     $this->extractor->setExcludedDirs($config->getExcludedDirs());
     $this->extractor->setExcludedNames($config->getExcludedNames());
     $this->extractor->setEnabledExtractors($config->getEnabledExtractors());
     $this->logger->info("Extracting translation keys");
     $this->scannedCatalogue = $this->extractor->extract();
     $this->scannedCatalogue->setLocale($config->getLocale());
     // merge existing messages into scanned messages
     foreach ($this->scannedCatalogue->getDomains() as $domainCatalogue) {
         foreach ($domainCatalogue->all() as $message) {
             if (!$this->existingCatalogue->has($message)) {
                 continue;
             }
             $existingMessage = clone $this->existingCatalogue->get($message->getId(), $message->getDomain());
             $existingMessage->mergeScanned($message);
             $this->scannedCatalogue->set($existingMessage, true);
         }
     }
     if ($this->config->isKeepOldMessages()) {
         foreach ($this->existingCatalogue->getDomains() as $domainCatalogue) {
             foreach ($domainCatalogue->all() as $message) {
                 if ($this->scannedCatalogue->has($message)) {
                     continue;
                 }
                 $this->scannedCatalogue->add($message);
             }
         }
     }
     //keep old translations translated
     if ($this->config->isKeepOldTranslationMessages()) {
         $locale = $this->scannedCatalogue->getLocale();
         /** @var MessageCatalogue $domainCatalogue */
         foreach ($this->scannedCatalogue->getDomains() as $domainCatalogue) {
             /** @var Message $message */
             foreach ($domainCatalogue->all() as $message) {
                 $translated = $this->translator->trans($message->getId(), array(), $message->getDomain(), $locale);
                 $message->setLocaleString($translated);
                 $message->setNew(false);
             }
         }
     }
 }
예제 #2
0
 /**
  * @param \Symfony\Component\HttpKernel\Log\LoggerInterface $logger
  */
 public function setLogger(LoggerInterface $logger)
 {
     $this->logger = $logger;
     $this->extractor->setLogger($logger);
 }