/** * Handle a language for a resource. * * @param TranslationResource $resource The resource to process. * * @param string $code The language code. * * @param string $translationMode The translation mode. * * @param OutputInterface $output The output interface to use. * * @return void */ private function handleLanguage(TranslationResource $resource, $code, $translationMode, OutputInterface $output) { $this->writeln($output, sprintf('Updating language <info>%s</info>', $code)); // Pull it. $data = $resource->fetchTranslation($code, $translationMode); if ($data) { $local = $this->getLocalXliffFile($resource, $code); $new = new XliffFile(null); $new->loadXML($data); foreach ($new->getKeys() as $key) { if ($value = $new->getSource($key)) { $local->setSource($key, $value); if ($value = $new->getTarget($key)) { $local->setTarget($key, $value); } } } foreach (array_diff($new->getKeys(), $local->getKeys()) as $key) { $this->writeln($output, sprintf('Language key <info>%s</info> seems to be orphaned, please check.', $key)); } if ($local->getKeys()) { if (!is_dir(dirname($local->getFileName()))) { mkdir(dirname($local->getFileName()), 0755, true); } $local->save(); } } }
/** * Fetches the target value from this entry. * * @return null|string */ public function getTarget() { return $this->doc->getTarget($this->getKey()); }