Started to work on some magic to extract translateable strings.
This commit is contained in:
parent
bceb212184
commit
e8c9144996
3 changed files with 78 additions and 7 deletions
26
extract_strings.php
Normal file
26
extract_strings.php
Normal 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();
|
||||
}
|
Reference in a new issue