/**
  * Create a xliff instance for the passed resource.
  *
  * @param TranslationResource $resource     The resource.
  *
  * @param string              $languageCode The language code.
  *
  * @return XliffFile
  */
 private function getLocalXliffFile(TranslationResource $resource, $languageCode)
 {
     $domain = substr($resource->getSlug(), strlen($this->prefix));
     $localFile = $this->txlang . DIRECTORY_SEPARATOR . substr($languageCode, 0, 2) . DIRECTORY_SEPARATOR . $domain . '.xlf';
     $local = new XliffFile($localFile);
     if (!file_exists($localFile)) {
         // Set base values.
         $local->setDataType('php');
         $local->setOriginal($domain);
         $local->setSrcLang($this->baselanguage);
         $local->setTgtLang(substr($languageCode, 0, 2));
     }
     return $local;
 }
 /**
  * Fetches the target value from this entry.
  *
  * @return null|string
  */
 public function getTarget()
 {
     return $this->doc->getTarget($this->getKey());
 }
 /**
  * {@inheritDoc}
  *
  * @throws \InvalidArgumentException When an unexpected domain has been found in the xliff file.
  */
 protected function processLanguage(OutputInterface $output, $language)
 {
     $this->writeln($output, sprintf('processing language: <info>%s</info>...', $language));
     $destinationFiles = array();
     foreach ($this->baseFiles as $file) {
         $this->writelnVerbose($output, sprintf('processing file: <info>%s</info>...', $file));
         $srcFile = $this->getLanguageBasePath() . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . $file;
         // not a file from transifex received yet.
         if (!file_exists($srcFile)) {
             continue;
         }
         $src = new XliffFile($srcFile);
         $domain = $src->getOriginal();
         if ($domain != basename($file, '.xlf')) {
             throw new \InvalidArgumentException(sprintf('Unexpected domain "%s" found in file "%s" instead of domain "%s"', $domain, $srcFile, basename($file, '.xlf')));
         }
         $dstFile = $domain . '.php';
         $destinationFiles[] = $dstFile;
         $dstDir = $this->getDestinationBasePath() . DIRECTORY_SEPARATOR . $language;
         if (!is_dir($dstDir)) {
             mkdir($dstDir, 0755, true);
         }
         $dest = new ContaoFile($dstDir . DIRECTORY_SEPARATOR . $dstFile);
         $changed = $this->convert($src, $dest);
         if ($changed) {
             $dest->setLanguage($language);
             $dest->setTransifexProject($this->project);
             $dest->setLastChange($src->getDate());
             if ($dest->getKeys()) {
                 $dest->save();
             } else {
                 unlink($dstDir . DIRECTORY_SEPARATOR . $dstFile);
             }
         }
     }
     $this->cleanupObsoleteFiles($output, $language, $destinationFiles);
 }
 /**
  * {@inheritDoc}
  */
 protected function processLanguage(OutputInterface $output, $language)
 {
     $this->writeln($output, sprintf('processing language: <info>%s</info>...', $language));
     $destinationFiles = array();
     foreach ($this->baseFiles as $file) {
         $this->writelnVerbose($output, sprintf('processing file: <info>%s</info>...', $file));
         $basFile = $this->getLanguageBasePath() . DIRECTORY_SEPARATOR . $this->baselanguage . DIRECTORY_SEPARATOR . $file;
         $srcFile = $this->getLanguageBasePath() . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . $file;
         $domain = basename($file, '.php');
         $dstFile = $domain . '.xlf';
         $destinationFiles[] = $dstFile;
         $src = new ContaoFile($srcFile, $output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG);
         $base = new ContaoFile($basFile, $output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG);
         $dstDir = $this->getDestinationBasePath() . DIRECTORY_SEPARATOR . $language;
         if (!is_dir($dstDir)) {
             mkdir($dstDir, 0755, true);
         }
         $dest = new XliffFile($dstDir . DIRECTORY_SEPARATOR . $dstFile);
         $dest->setDataType('php');
         $dest->setSrcLang($this->baselanguage);
         $dest->setTgtLang($language);
         $dest->setOriginal($domain);
         if (file_exists($srcFile)) {
             $time = filemtime($srcFile);
         } else {
             $time = filemtime($basFile);
         }
         $dest->setDate($time);
         $this->convert($output, $src, $dest, $base);
         if (is_file($dstDir . DIRECTORY_SEPARATOR . $dstFile) || $dest->getKeys()) {
             $dest->save();
         }
         if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
             $output->writeln($src->getDebugMessages());
             $output->writeln($base->getDebugMessages());
         }
     }
     $this->cleanupObsoleteFiles($output, $language, $destinationFiles);
 }