diff --git a/Twig/Gettext/Extractor.php b/Twig/Gettext/Extractor.php index e7fa1af..1feb75e 100644 --- a/Twig/Gettext/Extractor.php +++ b/Twig/Gettext/Extractor.php @@ -32,6 +32,12 @@ class Extractor */ protected $templates; + /** + * xgettext command like in terminal + * @var string + */ + protected $command; + /** * Gettext parameters. * @@ -57,6 +63,11 @@ public function addTemplate($path) $this->templates[] = $this->environment->getCacheFilename($path); } + public function setGettextCommand($command = "xgettext") + { + $this->command = $command; + } + public function addGettextParameter($parameter) { $this->parameters[] = $parameter; @@ -69,16 +80,21 @@ public function setGettextParameters(array $parameters) public function extract() { - $command = 'xgettext'; - $command .= ' '.join(' ', $this->parameters); - $command .= ' '.join(' ', $this->templates); - + # Generate xgettext path with params (XGETTEXT_PATH defined in twig-gettext-extractor file) + $this->command .= ' '.join(' ', $this->parameters); + $this->command .= ' '.join(' ', $this->templates); + $error = 0; - $output = system($command, $error); + + # Attention, if you have problems with function system() + # You can try turn off safe_mode in php.ini and if it not help + # try to use full path to xgettext command (like: "/usr/bin/ls") + $output = system($this->command, $error); + if (0 !== $error) { throw new \RuntimeException(sprintf( 'Gettext command "%s" failed with error code %s and output: %s', - $command, + $this->command, $error, $output )); diff --git a/composer.phar b/composer.phar new file mode 100755 index 0000000..415cf0a Binary files /dev/null and b/composer.phar differ diff --git a/twig-gettext-extractor b/twig-gettext-extractor index 6cc97c1..d6010d9 100755 --- a/twig-gettext-extractor +++ b/twig-gettext-extractor @@ -1,6 +1,5 @@ #!/usr/bin/env php setGettextCommand("xgettext"); + $extractor->extract();