#!/usr/bin/env php * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * Extracts translations from twig templates. * * @author Саша Стаменковић */ if (file_exists($a = __DIR__.'/../../autoload.php')) { require_once $a; } else { require_once __DIR__.'/vendor/autoload.php'; } $twig = new Twig_Environment(new Twig\Gettext\Loader\Filesystem('/'), array( 'cache' => '/tmp/cache/'.uniqid(), 'auto_reload' => true )); $twig->addExtension(new Symfony\Bridge\Twig\Extension\TranslationExtension( new Symfony\Component\Translation\Translator(null) )); $twig->addExtension(new Twig_Extensions_Extension_I18n()); $twig->addExtension(new Symfony\Bridge\Twig\Extension\RoutingExtension( new Twig\Gettext\Routing\Generator\UrlGenerator() )); $twig->addExtension(new Symfony\Bridge\Twig\Extension\FormExtension( new Symfony\Bridge\Twig\Form\TwigRenderer( new Symfony\Bridge\Twig\Form\TwigRendererEngine() ) )); // You can add more extensions here. array_shift($_SERVER['argv']); $addTemplate = false; $extractor = new Twig\Gettext\Extractor($twig); foreach ($_SERVER['argv'] as $arg) { if ('--files' == $arg) { $addTemplate = true; } else if ($addTemplate) { $extractor->addTemplate(getcwd().DIRECTORY_SEPARATOR.$arg); } else { $extractor->addGettextParameter($arg); } } $extractor->extract();