Format the results as xml
This commit is contained in:
parent
9555e84d1b
commit
bd79dc5a47
1 changed files with 47 additions and 1 deletions
|
@ -3,6 +3,20 @@ require 'vendor/autoload.php';
|
||||||
|
|
||||||
$translations = array();
|
$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
|
class MyNodeVisitor extends PHPParser_NodeVisitorAbstract
|
||||||
{
|
{
|
||||||
public function enterNode(PHPParser_Node $node) {
|
public function enterNode(PHPParser_Node $node) {
|
||||||
|
@ -36,4 +50,36 @@ foreach(glob('templates/*.twig') as $file) {
|
||||||
|
|
||||||
$translations = array_unique($translations);
|
$translations = array_unique($translations);
|
||||||
|
|
||||||
print_r($translations);
|
/*$xml = new SimpleXMLElement('');*/
|
||||||
|
|
||||||
|
$xml = <<<EOF
|
||||||
|
<?xml version='1.0' standalone='yes'?>
|
||||||
|
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2
|
||||||
|
xliff-core-1.2-transitional.xsd"
|
||||||
|
version="1.2">
|
||||||
|
<file source-language="de" datatype="plaintext" original="file.ext">
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</file>
|
||||||
|
</xliff>
|
||||||
|
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));
|
Reference in a new issue