]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/umpirsky/twig-gettext-extractor/twig-gettext-extractor
twig implementation
[github/wallabag/wallabag.git] / vendor / umpirsky / twig-gettext-extractor / twig-gettext-extractor
1 #!/usr/bin/env php
2 <?php
3
4 /**
5 * This file is part of the Twig Gettext utility.
6 *
7 * (c) Саша Стаменковић <umpirsky@gmail.com>
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 */
12
13 /**
14 * Extracts translations from twig templates.
15 *
16 * @author Саша Стаменковић <umpirsky@gmail.com>
17 */
18
19 if (file_exists($a = __DIR__.'/../../autoload.php')) {
20 require_once $a;
21 } else {
22 require_once __DIR__.'/vendor/autoload.php';
23 }
24
25 $twig = new Twig_Environment(new Twig\Gettext\Loader\Filesystem('/'), array(
26 'cache' => '/tmp/cache/'.uniqid(),
27 'auto_reload' => true
28 ));
29 $twig->addExtension(new Symfony\Bridge\Twig\Extension\TranslationExtension(
30 new Symfony\Component\Translation\Translator(null)
31 ));
32 $twig->addExtension(new Twig_Extensions_Extension_I18n());
33 $twig->addExtension(new Symfony\Bridge\Twig\Extension\RoutingExtension(
34 new Twig\Gettext\Routing\Generator\UrlGenerator()
35 ));
36 $twig->addExtension(new Symfony\Bridge\Twig\Extension\FormExtension(
37 new Symfony\Bridge\Twig\Form\TwigRenderer(
38 new Symfony\Bridge\Twig\Form\TwigRendererEngine()
39 )
40 ));
41 // You can add more extensions here.
42
43 array_shift($_SERVER['argv']);
44 $addTemplate = false;
45
46 $extractor = new Twig\Gettext\Extractor($twig);
47
48 foreach ($_SERVER['argv'] as $arg) {
49 if ('--files' == $arg) {
50 $addTemplate = true;
51 } else if ($addTemplate) {
52 $extractor->addTemplate(getcwd().DIRECTORY_SEPARATOR.$arg);
53 } else {
54 $extractor->addGettextParameter($arg);
55 }
56 }
57
58 $extractor->extract();