/** * 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; }
/** * {@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); }