Started to work on some magic to extract translateable strings.

This commit is contained in:
Tim Schumacher 2013-10-24 16:03:24 +02:00
parent bceb212184
commit e8c9144996
3 changed files with 78 additions and 7 deletions

26
extract_strings.php Normal file
View file

@ -0,0 +1,26 @@
<?php
require 'vendor/autoload.php';
class MyNodeVisitor extends PHPParser_NodeVisitorAbstract
{
public function enterNode(PHPParser_Node $node) {
if ($node instanceof PHPParser_Node_Expr_MethodCall) {
if ($node->name == 'trans') {
echo $node->args[0]->value->value."\n";
}
}
}
}
$file = file_get_contents('index.php');
$parser = new PHPParser_Parser(new PHPParser_Lexer);
$traverser = new PHPParser_NodeTraverser;
$traverser->addVisitor(new MyNodeVisitor);
try {
$stmts = $parser->parse($file);
$stmts = $traverser->traverse($stmts);
} catch (PHPParser_Error $e) {
echo 'Parse Error: ', $e->getMessage();
}