Apply the standard formating
This commit is contained in:
parent
1e980fb8c8
commit
fe537e6037
1 changed files with 12 additions and 10 deletions
|
@ -3,9 +3,10 @@ require 'vendor/autoload.php';
|
|||
|
||||
$translations = array();
|
||||
|
||||
function format_xml(&$simpleXmlObject){
|
||||
function format_xml(&$simpleXmlObject)
|
||||
{
|
||||
|
||||
if( ! is_object($simpleXmlObject) ){
|
||||
if (!is_object($simpleXmlObject)) {
|
||||
return "";
|
||||
}
|
||||
//Format XML to save indented tree rather than one line
|
||||
|
@ -19,7 +20,8 @@ function format_xml(&$simpleXmlObject){
|
|||
|
||||
class MyNodeVisitor extends PHPParser_NodeVisitorAbstract
|
||||
{
|
||||
public function enterNode(PHPParser_Node $node) {
|
||||
public function enterNode(PHPParser_Node $node)
|
||||
{
|
||||
global $translations;
|
||||
if ($node instanceof PHPParser_Node_Expr_MethodCall) {
|
||||
if ($node->name == 'trans') {
|
||||
|
@ -42,10 +44,10 @@ try {
|
|||
echo 'Parse Error: ', $e->getMessage();
|
||||
}
|
||||
|
||||
foreach(glob('templates/*.twig') as $file) {
|
||||
foreach (glob('templates/*.twig') as $file) {
|
||||
$content = file_get_contents($file);
|
||||
preg_match_all('/{% trans %}(.*){% endtrans %}/',$content,$matches);
|
||||
$translations = array_merge($translations,$matches[1]);
|
||||
preg_match_all('/{% trans %}(.*){% endtrans %}/', $content, $matches);
|
||||
$translations = array_merge($translations, $matches[1]);
|
||||
}
|
||||
|
||||
$translations = array_unique($translations);
|
||||
|
@ -72,13 +74,13 @@ $xml = new SimpleXMLElement($xml);
|
|||
|
||||
$id = 1;
|
||||
|
||||
foreach($translations as $translation) {
|
||||
foreach ($translations as $translation) {
|
||||
/** @var SimpleXMLElement $element */
|
||||
$element = $xml->file->body;
|
||||
$element = $element->addChild('trans-unit');
|
||||
$element->addAttribute('id',$id);
|
||||
$element->addAttribute('id', $id);
|
||||
$id++;
|
||||
$element->addChild('source',$translation);
|
||||
$element->addChild('source', $translation);
|
||||
}
|
||||
|
||||
|
||||
|
|
Reference in a new issue