diff --git a/bin/icingacli b/bin/icingacli index 19d786af7..1922c9706 100755 --- a/bin/icingacli +++ b/bin/icingacli @@ -1,4 +1,4 @@ -#!/usr/bin/php +#!/usr/bin/env php /dev/null || groupadd -r icingacmd @@ -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} diff --git a/modules/translation/application/clicommands/CompileCommand.php b/modules/translation/application/clicommands/CompileCommand.php index 036769175..e13b8b9f5 100644 --- a/modules/translation/application/clicommands/CompileCommand.php +++ b/modules/translation/application/clicommands/CompileCommand.php @@ -38,7 +38,7 @@ class CompileCommand extends TranslationCommand { $locale = $this->validateLocaleCode($this->params->shift()); - $helper = new GettextTranslationHelper($this->app, $locale); + $helper = $this->getTranslationHelper($locale); $helper->compileIcingaTranslation(); } @@ -61,7 +61,7 @@ class CompileCommand extends TranslationCommand $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); } } diff --git a/modules/translation/application/clicommands/RefreshCommand.php b/modules/translation/application/clicommands/RefreshCommand.php index 67cbf0296..7320b9651 100644 --- a/modules/translation/application/clicommands/RefreshCommand.php +++ b/modules/translation/application/clicommands/RefreshCommand.php @@ -38,7 +38,7 @@ class RefreshCommand extends TranslationCommand { $locale = $this->validateLocaleCode($this->params->shift()); - $helper = new GettextTranslationHelper($this->app, $locale); + $helper = $this->getTranslationHelper($locale); $helper->updateIcingaTranslations(); } @@ -61,7 +61,7 @@ class RefreshCommand extends TranslationCommand $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); } } diff --git a/modules/translation/library/Translation/Cli/TranslationCommand.php b/modules/translation/library/Translation/Cli/TranslationCommand.php index e11d03d29..48f7d6ed2 100644 --- a/modules/translation/library/Translation/Cli/TranslationCommand.php +++ b/modules/translation/library/Translation/Cli/TranslationCommand.php @@ -6,12 +6,27 @@ namespace Icinga\Module\Translation\Cli; 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 * @@ -46,7 +61,7 @@ class TranslationCommand extends Command { $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 diff --git a/modules/translation/library/Translation/Util/GettextTranslationHelper.php b/modules/translation/library/Translation/Util/GettextTranslationHelper.php index cbeaa2d6b..c3a6d206e 100644 --- a/modules/translation/library/Translation/Util/GettextTranslationHelper.php +++ b/modules/translation/library/Translation/Util/GettextTranslationHelper.php @@ -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 @@ -19,6 +20,13 @@ class GettextTranslationHelper */ const FILE_ENCODING = 'UTF-8'; + /** + * Config + * + * @var Config + */ + protected $config; + /** * The source files to parse * @@ -71,6 +79,13 @@ class GettextTranslationHelper */ private $moduleDir; + /** + * Path to the Icinga library + * + * @var string + */ + protected $libDir; + /** * The path to the file catalog * @@ -102,9 +117,33 @@ class GettextTranslationHelper { $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 */ @@ -211,7 +250,12 @@ class GettextTranslationHelper 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)) { @@ -233,7 +277,7 @@ class GettextTranslationHelper implode( ' ', array( - '/usr/bin/xgettext', + $this->getConfig()->get('translation', 'xgettext', '/usr/bin/env xgettext'), '--language=PHP', '--keyword=translate', '--keyword=translate:1,2c', @@ -360,7 +404,7 @@ class GettextTranslationHelper $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; @@ -414,7 +458,7 @@ class GettextTranslationHelper implode( ' ', array( - '/usr/bin/msgfmt', + $this->getConfig()->get('translation', 'msgfmt', '/usr/bin/env msgfmt'), '-o ' . $targetPath, $this->tablePath ) diff --git a/packages/files/config/modules/translation/config.ini b/packages/files/config/modules/translation/config.ini new file mode 100644 index 000000000..5bdf37b0c --- /dev/null +++ b/packages/files/config/modules/translation/config.ini @@ -0,0 +1,4 @@ +[translation] +msgmerge = /usr/bin/msgmerge +xgettext = /usr/bin/xgettext +msgfmt = /usr/bin/msgfmt