Skip to content

xgettext path #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions Twig/Gettext/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class Extractor
*/
protected $templates;

/**
* xgettext command like in terminal
* @var string
*/
protected $command;

/**
* Gettext parameters.
*
Expand All @@ -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;
Expand All @@ -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
));
Expand Down
Binary file added composer.phar
Binary file not shown.
7 changes: 6 additions & 1 deletion twig-gettext-extractor
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env php
<?php

/**
* This file is part of the Twig Gettext utility.
*
Expand Down Expand Up @@ -55,4 +54,10 @@ foreach ($_SERVER['argv'] as $arg) {
}
}

# Default value for path it's "xgettext".
# If you have problems with it on Linux or OS X, you can try to
# use command [$ which xgettext] in terminal and copy full path to xgettext here.
# For example for in OS X it's look like "/opt/local/bin/xgettext"
$extractor->setGettextCommand("xgettext");

$extractor->extract();