* @package tao */ class tao_helpers_translation_StructureExtractor extends tao_helpers_translation_TranslationExtractor { /** * Extracts the translation units from a structures.xml file. * Translation Units can be retrieved after extraction by calling the getTranslationUnits * method. * * @access public * @author Jerome Bogaerts * @throws tao_helpers_translation_TranslationException If an error occurs. */ public function extract() { $translationUnits = []; foreach ($this->getPaths() as $file) { $xml = new \SimpleXMLElement($file, null, true); if ($xml instanceof SimpleXMLElement) { // look up for "name" attributes of structure elements. $nodes = $xml->xpath("//structure[@name]|//section[@name]"); foreach ($nodes as $node) { if (isset($node['name'])) { $nodeName = (string)$node['name']; $newTranslationUnit = new tao_helpers_translation_POTranslationUnit(); $newTranslationUnit->setSource($nodeName); $newTranslationUnit->addFlag('tao-public'); $translationUnits[$nodeName] = $newTranslationUnit; } } // look up for "name" attributes of action elements. $nodes = $xml->xpath("//action[@name]|//tree[@name]"); foreach ($nodes as $node) { if (isset($node['name'])) { $nodeName = (string)$node['name']; $newTranslationUnit = new tao_helpers_translation_POTranslationUnit(); $newTranslationUnit->setSource($nodeName); $newTranslationUnit->addFlag('tao-public'); $translationUnits[$nodeName] = $newTranslationUnit; } } // look up for "description" elements. $nodes = $xml->xpath("//description"); foreach ($nodes as $node) { if ((string)$node != '') { $newTranslationUnit = new tao_helpers_translation_POTranslationUnit(); $newTranslationUnit->setSource((string)$node); $newTranslationUnit->addFlag('tao-public'); $translationUnits[(string)$node] = $newTranslationUnit; } } // look up for "action" elements inside a toolbar $nodes = $xml->xpath("//toolbar/toolbaraction"); foreach ($nodes as $node) { $nodeValue = (string)$node; if (trim($nodeValue) != '' && !array_key_exists($nodeValue, $translationUnits)) { $newTranslationUnit = new tao_helpers_translation_POTranslationUnit(); $newTranslationUnit->setSource($nodeValue); $newTranslationUnit->addFlag('tao-public'); $translationUnits[$nodeValue] = $newTranslationUnit; } } // look up for the "title" attr of an "action" element inside a toolbar $nodes = $xml->xpath("//toolbar/toolbaraction[@title]"); foreach ($nodes as $node) { if (isset($node['title'])) { $nodeTitle = (string)$node['title']; $newTranslationUnit = new tao_helpers_translation_POTranslationUnit(); $newTranslationUnit->setSource($nodeTitle); $newTranslationUnit->addFlag('tao-public'); $translationUnits[$nodeTitle] = $newTranslationUnit; } } // look up for the "entrypoint" elements $nodes = $xml->xpath("//entrypoint"); foreach ($nodes as $node) { if (isset($node['title'])) { $nodeTitle = (string)$node['title']; $newTranslationUnit = new tao_helpers_translation_POTranslationUnit(); $newTranslationUnit->setSource($nodeTitle); $newTranslationUnit->addFlag('tao-public'); $translationUnits[$nodeTitle] = $newTranslationUnit; } if (isset($node['label'])) { $nodeLabel = (string)$node['label']; $newTranslationUnit = new tao_helpers_translation_POTranslationUnit(); $newTranslationUnit->setSource($nodeLabel); $newTranslationUnit->addFlag('tao-public'); $translationUnits[$nodeTitle] = $newTranslationUnit; } } } } $this->setTranslationUnits(array_values($translationUnits)); } }