4 * This file is part of the Twig Gettext utility.
6 * (c) Саша Стаменковић <umpirsky@gmail.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Twig\Gettext
;
14 use Symfony\Component\Filesystem\Filesystem
;
17 * Extracts translations from twig templates.
19 * @author Саша Стаменковић <umpirsky@gmail.com>
24 * @var \Twig_Environment
26 protected $environment;
29 * Template cached file names.
40 protected $parameters;
42 public function __construct(\Twig_Environment
$environment)
44 $this->environment
= $environment;
48 protected function reset()
50 $this->templates
= array();
51 $this->parameters
= array();
54 public function addTemplate($path)
56 $this->environment
->loadTemplate($path);
57 $this->templates
[] = $this->environment
->getCacheFilename($path);
60 public function addGettextParameter($parameter)
62 $this->parameters
[] = $parameter;
65 public function setGettextParameters(array $parameters)
67 $this->parameters
= $parameters;
70 public function extract()
72 $command = 'xgettext';
73 $command .= ' '.join(' ', $this->parameters
);
74 $command .= ' '.join(' ', $this->templates
);
77 $output = system($command, $error);
79 throw new \
RuntimeException(sprintf(
80 'Gettext command "%s" failed with error code %s and output: %s',
90 public function __destruct()
92 $filesystem = new Filesystem();
93 $filesystem->remove($this->environment
->getCache());