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

View file

@ -6,6 +6,7 @@
"symfony/translation": "~2.3", "symfony/translation": "~2.3",
"symfony/config": "~2.3", "symfony/config": "~2.3",
"swiftmailer/swiftmailer": "~5.0", "swiftmailer/swiftmailer": "~5.0",
"guzzle/guzzle": "~3.7" "guzzle/guzzle": "~3.7",
"nikic/php-parser": "~0.9"
} }
} }

56
composer.lock generated
View file

@ -3,7 +3,7 @@
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
], ],
"hash": "e9bc445899f0e8b6c7b1a68e3106d576", "hash": "ac3725b9d9d876fb79ca80e454872995",
"packages": [ "packages": [
{ {
"name": "guzzle/guzzle", "name": "guzzle/guzzle",
@ -97,6 +97,50 @@
], ],
"time": "2013-10-02 20:47:00" "time": "2013-10-02 20:47:00"
}, },
{
"name": "nikic/php-parser",
"version": "v0.9.4",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "1e5e280ae88a27effa2ae4aa2bd088494ed8594f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/1e5e280ae88a27effa2ae4aa2bd088494ed8594f",
"reference": "1e5e280ae88a27effa2ae4aa2bd088494ed8594f",
"shasum": ""
},
"require": {
"php": ">=5.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.9-dev"
}
},
"autoload": {
"psr-0": {
"PHPParser": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Nikita Popov"
}
],
"description": "A PHP parser written in PHP",
"keywords": [
"parser",
"php"
],
"time": "2013-08-25 17:11:40"
},
{ {
"name": "pimple/pimple", "name": "pimple/pimple",
"version": "v1.0.2", "version": "v1.0.2",
@ -821,16 +865,16 @@
}, },
{ {
"name": "twig/twig", "name": "twig/twig",
"version": "v1.14.0", "version": "v1.14.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/fabpot/Twig.git", "url": "https://github.com/fabpot/Twig.git",
"reference": "224fc55635d544a2ec8edb3592be18db5a093f59" "reference": "8873d7593ad7c120004f177c0fd01459b383c9cb"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/fabpot/Twig/zipball/224fc55635d544a2ec8edb3592be18db5a093f59", "url": "https://api.github.com/repos/fabpot/Twig/zipball/8873d7593ad7c120004f177c0fd01459b383c9cb",
"reference": "224fc55635d544a2ec8edb3592be18db5a093f59", "reference": "8873d7593ad7c120004f177c0fd01459b383c9cb",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -866,7 +910,7 @@
"keywords": [ "keywords": [
"templating" "templating"
], ],
"time": "2013-10-03 06:41:20" "time": "2013-10-15 19:17:38"
} }
], ],
"packages-dev": [ "packages-dev": [

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();
}