From cf91478b65c8e0da3a889e23a12a3b195bff843b Mon Sep 17 00:00:00 2001 From: xert Date: Fri, 26 Jun 2015 16:26:05 +0200 Subject: [PATCH 1/9] Use /usr/bin/env php in the icingacli for source installations Signed-off-by: Eric Lippmann --- bin/icingacli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 Date: Thu, 30 Jul 2015 15:47:35 +0200 Subject: [PATCH 2/9] translation: Set config on the translation helper Installations from package will provide a config for the translation module which defines the appropriate gettext tools paths. refs #9615 --- .../clicommands/CompileCommand.php | 4 +-- .../clicommands/RefreshCommand.php | 4 +-- .../Translation/Cli/TranslationCommand.php | 17 ++++++++- .../Util/GettextTranslationHelper.php | 35 +++++++++++++++++-- 4 files changed, 53 insertions(+), 7 deletions(-) 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..53f9aff17 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 * @@ -105,6 +113,29 @@ class GettextTranslationHelper $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 */ From 7160eb600a8619930c04df56702ed6658712e248 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 30 Jul 2015 15:51:41 +0200 Subject: [PATCH 3/9] translation: Load msgmerge path from config or default to /usr/bin/env msgmerge refs #9615 --- .../library/Translation/Util/GettextTranslationHelper.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/translation/library/Translation/Util/GettextTranslationHelper.php b/modules/translation/library/Translation/Util/GettextTranslationHelper.php index 53f9aff17..d4742e7d0 100644 --- a/modules/translation/library/Translation/Util/GettextTranslationHelper.php +++ b/modules/translation/library/Translation/Util/GettextTranslationHelper.php @@ -242,7 +242,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 php'), + $this->tablePath, + $this->templatePath + )); } else { if ((!is_dir(dirname($this->tablePath)) && !@mkdir(dirname($this->tablePath), 0755, true)) || !rename($this->templatePath, $this->tablePath)) { From c9c97f3c61d9175c1008ce9b2c54d35f9df9f21b Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 30 Jul 2015 15:53:13 +0200 Subject: [PATCH 4/9] translation: Load xgettext path from config or default to /usr/bin/env xgettext refs #9615 --- .../library/Translation/Util/GettextTranslationHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/translation/library/Translation/Util/GettextTranslationHelper.php b/modules/translation/library/Translation/Util/GettextTranslationHelper.php index d4742e7d0..5e8c8d82c 100644 --- a/modules/translation/library/Translation/Util/GettextTranslationHelper.php +++ b/modules/translation/library/Translation/Util/GettextTranslationHelper.php @@ -269,7 +269,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', From d4c7261562c3afeb922c02897423212b38b8f03e Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 30 Jul 2015 15:53:39 +0200 Subject: [PATCH 5/9] translation: Fix msgmerge default refs #9615 --- .../library/Translation/Util/GettextTranslationHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/translation/library/Translation/Util/GettextTranslationHelper.php b/modules/translation/library/Translation/Util/GettextTranslationHelper.php index 5e8c8d82c..0993803bc 100644 --- a/modules/translation/library/Translation/Util/GettextTranslationHelper.php +++ b/modules/translation/library/Translation/Util/GettextTranslationHelper.php @@ -244,7 +244,7 @@ class GettextTranslationHelper if (is_file($this->tablePath)) { shell_exec(sprintf( '%s --update %s %s 2>&1', - $this->getConfig()->get('translation', 'msgmerge', '/usr/bin/env php'), + $this->getConfig()->get('translation', 'msgmerge', '/usr/bin/env msgmerge'), $this->tablePath, $this->templatePath )); From 8d137aa5752cb478a13c17d69d0272c61af3ab06 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 30 Jul 2015 15:55:05 +0200 Subject: [PATCH 6/9] translation: Load msgfmt path from config or default to /usr/bin/env msgfmt refs #9615 --- .../library/Translation/Util/GettextTranslationHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/translation/library/Translation/Util/GettextTranslationHelper.php b/modules/translation/library/Translation/Util/GettextTranslationHelper.php index 0993803bc..c36d54aa2 100644 --- a/modules/translation/library/Translation/Util/GettextTranslationHelper.php +++ b/modules/translation/library/Translation/Util/GettextTranslationHelper.php @@ -450,7 +450,7 @@ class GettextTranslationHelper implode( ' ', array( - '/usr/bin/msgfmt', + $this->getConfig()->get('translation', 'msgfmt', '/usr/bin/env msgfmt'), '-o ' . $targetPath, $this->tablePath ) From b9f16b844b8eb5bf293bdea870abad3a5e2e9b11 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 30 Jul 2015 15:57:21 +0200 Subject: [PATCH 7/9] translation: Add config file for packages refs #9615 --- packages/files/config/modules/translation/config.ini | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 packages/files/config/modules/translation/config.ini 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 From cc0dfedb3160f33e03e18b2e4580817c1e0ea62d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 30 Jul 2015 16:32:00 +0200 Subject: [PATCH 8/9] RPM: Install translation config refs #9615 --- icingaweb2.spec | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/icingaweb2.spec b/icingaweb2.spec index e3513e979..3ea135589 100644 --- a/icingaweb2.spec +++ b/icingaweb2.spec @@ -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 @@ -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 @@ -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} From 834017f6e539fd09a153a0a5c2cf1b7cea3862b1 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 31 Jul 2015 11:30:26 +0200 Subject: [PATCH 9/9] translation: Always use the correct path to the Icinga library in the translation helper refs #9615 --- .../Translation/Util/GettextTranslationHelper.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/translation/library/Translation/Util/GettextTranslationHelper.php b/modules/translation/library/Translation/Util/GettextTranslationHelper.php index c36d54aa2..c3a6d206e 100644 --- a/modules/translation/library/Translation/Util/GettextTranslationHelper.php +++ b/modules/translation/library/Translation/Util/GettextTranslationHelper.php @@ -79,6 +79,13 @@ class GettextTranslationHelper */ private $moduleDir; + /** + * Path to the Icinga library + * + * @var string + */ + protected $libDir; + /** * The path to the file catalog * @@ -110,6 +117,7 @@ class GettextTranslationHelper { $this->moduleMgr = $bootstrap->getModuleManager()->loadEnabledModules(); $this->appDir = $bootstrap->getApplicationDir(); + $this->libDir = $bootstrap->getLibraryDir('Icinga'); $this->locale = $locale; } @@ -396,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;