diff --git a/tools/extract_strings.php b/tools/extract_strings.php index df661f1..e50fbbe 100644 --- a/tools/extract_strings.php +++ b/tools/extract_strings.php @@ -3,6 +3,20 @@ require 'vendor/autoload.php'; $translations = array(); +function format_xml(&$simpleXmlObject){ + + if( ! is_object($simpleXmlObject) ){ + return ""; + } + //Format XML to save indented tree rather than one line + $dom = new DOMDocument('1.0'); + $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; + $dom->loadXML($simpleXmlObject->asXML()); + + return $dom->saveXML(); +} + class MyNodeVisitor extends PHPParser_NodeVisitorAbstract { public function enterNode(PHPParser_Node $node) { @@ -36,4 +50,36 @@ foreach(glob('templates/*.twig') as $file) { $translations = array_unique($translations); -print_r($translations); \ No newline at end of file +/*$xml = new SimpleXMLElement('');*/ + +$xml = << + + + + + + +EOF; + +$xml = new SimpleXMLElement($xml); + +//print_r($xml); + +$id = 1; + +foreach($translations as $translation) { + /** @var SimpleXMLElement $element */ + $element = $xml->file->body; + $element = $element->addChild('trans-unit'); + $element->addAttribute('id',$id); + $id++; + $element->addChild('source',$translation); +} + + +print_r(format_xml($xml)); \ No newline at end of file