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 */