langCode = $langCode; $this->extension = $extension; } public function getIterator() { $iterator = new \AppendIterator(); // english pack is always empty since in default rdfs if ($this->langCode != 'en-US') { foreach ($this->extension->getManifest()->getInstallModelFiles() as $rdfpath) { $modelId = FileModel::getModelIdFromXml($rdfpath); $candidate = $this->extension->getDir() . 'locales' . DIRECTORY_SEPARATOR . $this->langCode . DIRECTORY_SEPARATOR . basename($rdfpath) . '.po'; if (file_exists($candidate)) { $iterator->append($this->getTriplesFromFile($candidate, $modelId)); } } } return $iterator; } protected function getTriplesFromFile($file, $modelId) { $translationFileReader = new tao_helpers_translation_POFileReader($file); $translationFileReader->read(); $translationFile = $translationFileReader->getTranslationFile(); /** @var tao_helpers_translation_POTranslationUnit $tu */ $triples = []; foreach ($translationFile->getTranslationUnits() as $tu) { $annotations = $tu->getAnnotations(); $about = isset($annotations['po-translator-comments']) ? $annotations['po-translator-comments'] : null; if ($about && common_Utils::isUri($about) && in_array($tu->getContext(), [OntologyRdfs::RDFS_LABEL, OntologyRdfs::RDFS_COMMENT])) { $triple = new \core_kernel_classes_Triple(); $triple->subject = $about; $triple->predicate = $tu->getContext(); $triple->object = $tu->getTarget() ? $tu->getTarget() : $tu->getSource(); $triple->lg = $tu->getTargetLanguage(); $triple->modelid = $modelId; $triples[] = $triple; } } return new \ArrayIterator($triples); } }