Skip to content

Commit

Permalink
Merge branch 'bugfix/env-in-source-9615'
Browse files Browse the repository at this point in the history
fixes #9615
  • Loading branch information
lippserd committed Jul 31, 2015
2 parents c5b5d3c + 834017f commit f4c7fd5
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bin/icingacli
@@ -1,4 +1,4 @@
#!/usr/bin/php
#!/usr/bin/env php
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */

Expand Down
6 changes: 4 additions & 2 deletions icingaweb2.spec
Expand Up @@ -172,7 +172,7 @@ Icinga Web 2 vendor library Parsedown

%install
rm -rf %{buildroot}
mkdir -p %{buildroot}/{%{basedir}/{modules,library/vendor,public},%{bindir},%{configdir}/modules/setup,%{logdir},%{phpdir},%{wwwconfigdir},%{_sysconfdir}/bash_completion.d,%{docsdir}}
mkdir -p %{buildroot}/{%{basedir}/{modules,library/vendor,public},%{bindir},%{configdir}/modules,%{logdir},%{phpdir},%{wwwconfigdir},%{_sysconfdir}/bash_completion.d,%{docsdir}}
cp -prv application doc %{buildroot}/%{basedir}
cp -pv etc/bash_completion.d/icingacli %{buildroot}/%{_sysconfdir}/bash_completion.d/icingacli
cp -prv modules/{monitoring,setup,doc,translation} %{buildroot}/%{basedir}/modules
Expand All @@ -183,7 +183,7 @@ cp -pv packages/files/apache/icingaweb2.conf %{buildroot}/%{wwwconfigdir}/icinga
cp -pv packages/files/bin/icingacli %{buildroot}/%{bindir}
cp -pv packages/files/public/index.php %{buildroot}/%{basedir}/public
cp -prv etc/schema %{buildroot}/%{docsdir}
cp -prv packages/files/config/modules/setup %{buildroot}/%{configdir}/modules/
cp -prv packages/files/config/modules/{setup,translation} %{buildroot}/%{configdir}/modules

%pre
getent group icingacmd >/dev/null || groupadd -r icingacmd
Expand Down Expand Up @@ -212,6 +212,8 @@ rm -rf %{buildroot}
%attr(2775,root,%{icingawebgroup}) %dir %{logdir}
%attr(2770,root,%{icingawebgroup}) %config(noreplace) %dir %{configdir}/modules/setup
%attr(0660,root,%{icingawebgroup}) %config(noreplace) %{configdir}/modules/setup/config.ini
%attr(2770,root,%{icingawebgroup}) %config(noreplace) %dir %{configdir}/modules/translation
%attr(0660,root,%{icingawebgroup}) %config(noreplace) %{configdir}/modules/translation/config.ini
%{docsdir}
%docdir %{docsdir}

Expand Down
Expand Up @@ -38,7 +38,7 @@ public function icingaAction()
{
$locale = $this->validateLocaleCode($this->params->shift());

$helper = new GettextTranslationHelper($this->app, $locale);
$helper = $this->getTranslationHelper($locale);
$helper->compileIcingaTranslation();
}

Expand All @@ -61,7 +61,7 @@ public function moduleAction()
$module = $this->validateModuleName($this->params->shift());
$locale = $this->validateLocaleCode($this->params->shift());

$helper = new GettextTranslationHelper($this->app, $locale);
$helper = $this->getTranslationHelper($locale);
$helper->compileModuleTranslation($module);
}
}
Expand Up @@ -38,7 +38,7 @@ public function icingaAction()
{
$locale = $this->validateLocaleCode($this->params->shift());

$helper = new GettextTranslationHelper($this->app, $locale);
$helper = $this->getTranslationHelper($locale);
$helper->updateIcingaTranslations();
}

Expand All @@ -61,7 +61,7 @@ public function moduleAction()
$module = $this->validateModuleName($this->params->shift());
$locale = $this->validateLocaleCode($this->params->shift());

$helper = new GettextTranslationHelper($this->app, $locale);
$helper = $this->getTranslationHelper($locale);
$helper->updateModuleTranslations($module);
}
}
Expand Up @@ -6,12 +6,27 @@
use Exception;
use Icinga\Cli\Command;
use Icinga\Exception\IcingaException;
use Icinga\Module\Translation\Util\GettextTranslationHelper;

/**
* Base class for translation commands
*/
class TranslationCommand extends Command
{
/**
* Get the gettext translation helper
*
* @param string $locale
*
* @return GettextTranslationHelper
*/
public function getTranslationHelper($locale)
{
$helper = new GettextTranslationHelper($this->app, $locale);
$helper->setConfig($this->Config());
return $helper;
}

/**
* Check whether the given locale code is valid
*
Expand Down Expand Up @@ -46,7 +61,7 @@ public function validateModuleName($name)
{
$enabledModules = $this->app->getModuleManager()->listEnabledModules();

if (!in_array($name, $enabledModules)) {
if (! in_array($name, $enabledModules)) {
throw new IcingaException(
'Module with name \'%s\' not found or is not enabled',
$name
Expand Down
Expand Up @@ -4,10 +4,11 @@
namespace Icinga\Module\Translation\Util;

use Exception;
use Icinga\Application\ApplicationBootstrap;
use Icinga\Application\Config;
use Icinga\Application\Modules\Manager;
use Icinga\Exception\IcingaException;
use Icinga\Util\File;
use Icinga\Application\Modules\Manager;
use Icinga\Application\ApplicationBootstrap;

/**
* This class provides some useful utility functions to handle gettext translations
Expand All @@ -19,6 +20,13 @@ class GettextTranslationHelper
*/
const FILE_ENCODING = 'UTF-8';

/**
* Config
*
* @var Config
*/
protected $config;

/**
* The source files to parse
*
Expand Down Expand Up @@ -71,6 +79,13 @@ class GettextTranslationHelper
*/
private $moduleDir;

/**
* Path to the Icinga library
*
* @var string
*/
protected $libDir;

/**
* The path to the file catalog
*
Expand Down Expand Up @@ -102,9 +117,33 @@ public function __construct(ApplicationBootstrap $bootstrap, $locale)
{
$this->moduleMgr = $bootstrap->getModuleManager()->loadEnabledModules();
$this->appDir = $bootstrap->getApplicationDir();
$this->libDir = $bootstrap->getLibraryDir('Icinga');
$this->locale = $locale;
}

/**
* Get the config
*
* @return Config
*/
public function getConfig()
{
return $this->config;
}

/**
* Set the config
*
* @param Config $config
*
* @return $this
*/
public function setConfig(Config $config)
{
$this->config = $config;
return $this;
}

/**
* Update the translation table for the main application
*/
Expand Down Expand Up @@ -211,7 +250,12 @@ public function compileModuleTranslation($module)
private function updateTranslationTable()
{
if (is_file($this->tablePath)) {
shell_exec(sprintf('/usr/bin/msgmerge --update %s %s 2>&1', $this->tablePath, $this->templatePath));
shell_exec(sprintf(
'%s --update %s %s 2>&1',
$this->getConfig()->get('translation', 'msgmerge', '/usr/bin/env msgmerge'),
$this->tablePath,
$this->templatePath
));
} else {
if ((!is_dir(dirname($this->tablePath)) && !@mkdir(dirname($this->tablePath), 0755, true)) ||
!rename($this->templatePath, $this->tablePath)) {
Expand All @@ -233,7 +277,7 @@ private function createTemplateFile()
implode(
' ',
array(
'/usr/bin/xgettext',
$this->getConfig()->get('translation', 'xgettext', '/usr/bin/env xgettext'),
'--language=PHP',
'--keyword=translate',
'--keyword=translate:1,2c',
Expand Down Expand Up @@ -360,7 +404,7 @@ private function createFileCatalog()
$this->getSourceFileNames($this->moduleDir, $catalog);
} else {
$this->getSourceFileNames($this->appDir, $catalog);
$this->getSourceFileNames(realpath($this->appDir . '/../library/Icinga'), $catalog);
$this->getSourceFileNames($this->libDir, $catalog);
}
} catch (Exception $error) {
throw $error;
Expand Down Expand Up @@ -414,7 +458,7 @@ private function compileTranslationTable()
implode(
' ',
array(
'/usr/bin/msgfmt',
$this->getConfig()->get('translation', 'msgfmt', '/usr/bin/env msgfmt'),
'-o ' . $targetPath,
$this->tablePath
)
Expand Down
4 changes: 4 additions & 0 deletions packages/files/config/modules/translation/config.ini
@@ -0,0 +1,4 @@
[translation]
msgmerge = /usr/bin/msgmerge
xgettext = /usr/bin/xgettext
msgfmt = /usr/bin/msgfmt

0 comments on commit f4c7fd5

Please sign in to comment.