From 8fe282b9aa4ab4301b8c19d7537027d185237104 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 28 May 2021 13:55:03 +0200 Subject: [PATCH] translation: Only allow to generate module locales --- .../clicommands/CompileCommand.php | 39 ++------- .../clicommands/RefreshCommand.php | 39 ++------- modules/translation/doc/03-Translation.md | 9 +-- .../Util/GettextTranslationHelper.php | 80 ++----------------- modules/translation/module.info | 8 +- 5 files changed, 27 insertions(+), 148 deletions(-) diff --git a/modules/translation/application/clicommands/CompileCommand.php b/modules/translation/application/clicommands/CompileCommand.php index 52047db2a..840800950 100644 --- a/modules/translation/application/clicommands/CompileCommand.php +++ b/modules/translation/application/clicommands/CompileCommand.php @@ -4,48 +4,21 @@ namespace Icinga\Module\Translation\Clicommands; use Icinga\Module\Translation\Cli\TranslationCommand; -use Icinga\Module\Translation\Util\GettextTranslationHelper; /** * Translation compiler * - * This command will compile the PO-file of a domain. The actions below allow - * you to select a particular domain for which the PO-file should be compiled. + * This command will compile gettext catalogs of modules. * - * Domains are the global one 'icinga' and all available and enabled modules - * identified by their name. - * - * Once a PO-file is compiled its content is used by Icinga Web 2 to display + * Once a catalog is compiled its content is used by Icinga Web 2 to display * messages in the configured language. */ class CompileCommand extends TranslationCommand { /** - * Compile the global domain + * Compile a module gettext catalog * - * This will compile the PO-file of the global 'icinga' domain. - * - * USAGE: - * - * icingacli translation compile icinga - * - * EXAMPLES: - * - * icingacli translation compile icinga de_DE - * icingacli translation compile icinga fr_FR - */ - public function icingaAction() - { - $locale = $this->validateLocaleCode($this->params->shift()); - - $helper = $this->getTranslationHelper($locale); - $helper->compileIcingaTranslation(); - } - - /** - * Compile a module domain - * - * This will compile the PO-file of the given module domain. + * This will compile the catalog of the given module and locale. * * USAGE: * @@ -53,8 +26,8 @@ class CompileCommand extends TranslationCommand * * EXAMPLES: * - * icingacli translation compile monitoring de_DE - * icingacli trnslations compile monitoring de_DE + * icingacli translation compile demo de_DE + * icingacli translation compile demo fr_FR */ public function moduleAction() { diff --git a/modules/translation/application/clicommands/RefreshCommand.php b/modules/translation/application/clicommands/RefreshCommand.php index bd22065cb..b4b2dc0d3 100644 --- a/modules/translation/application/clicommands/RefreshCommand.php +++ b/modules/translation/application/clicommands/RefreshCommand.php @@ -4,48 +4,21 @@ namespace Icinga\Module\Translation\Clicommands; use Icinga\Module\Translation\Cli\TranslationCommand; -use Icinga\Module\Translation\Util\GettextTranslationHelper; /** * Translation updater * - * This command will create a new or update any existing PO-file of a domain. The - * actions below allow to select a particular domain for whom to touch the PO-file. + * This command will create a new or update any existing gettext catalog of a module. * - * Domains are the global one 'icinga' and all available and enabled modules - * identified by their name. - * - * Once a PO-file has been created/updated one can open it with a editor for + * Once a catalog has been created/updated one can open it with a editor for * PO-files and start with the actual translation. */ class RefreshCommand extends TranslationCommand { /** - * Touch the global domain + * Generate or update a module gettext catalog * - * This will create/update the PO-file of the global 'icinga' domain. - * - * USAGE: - * - * icingacli translation refresh icinga - * - * EXAMPLES: - * - * icingacli translation refresh icinga de_DE - * icingacli translation refresh icinga fr_FR - */ - public function icingaAction() - { - $locale = $this->validateLocaleCode($this->params->shift()); - - $helper = $this->getTranslationHelper($locale); - $helper->updateIcingaTranslations(); - } - - /** - * Touch a module domain - * - * This will create/update the PO-file of the given module domain. + * This will create/update the PO-file of the given module and locale. * * USAGE: * @@ -53,8 +26,8 @@ class RefreshCommand extends TranslationCommand * * EXAMPLES: * - * icingacli translation refresh module monitoring de_DE - * icingacli translation refresh module monitoring fr_FR + * icingacli translation refresh module demo de_DE + * icingacli translation refresh module demo fr_FR */ public function moduleAction() { diff --git a/modules/translation/doc/03-Translation.md b/modules/translation/doc/03-Translation.md index 46260b7a5..1ea65bde0 100644 --- a/modules/translation/doc/03-Translation.md +++ b/modules/translation/doc/03-Translation.md @@ -1,13 +1,12 @@ # Introduction -Icinga Web 2 provides localization out of the box - for the core application and the modules, that means -that you can with a lightness use existent localizations, update or even create you own localizations. +Icinga Web 2 provides localization out of the box - for itself and the core modules. +This module is for third party module developers to aid them to localize their work. The chapters [Translation for Developers](03-Translation.md#module-translation-developers), [Translation for Translators](03-Translation.md#module-translation-translators) and -[Testing Translations](03-Translation.md#module-translation-tests) will introduce and explain you, how to take -part on localizing Icinga Web 2 for different languages and how to use the -`translation module` to make your life much easier. +[Testing Translations](03-Translation.md#module-translation-tests) will introduce and +explain you, how to take part on localizing modules to different languages. ## Translation for Developers diff --git a/modules/translation/library/Translation/Util/GettextTranslationHelper.php b/modules/translation/library/Translation/Util/GettextTranslationHelper.php index 1c8d04de6..90b8f1104 100644 --- a/modules/translation/library/Translation/Util/GettextTranslationHelper.php +++ b/modules/translation/library/Translation/Util/GettextTranslationHelper.php @@ -65,13 +65,6 @@ class GettextTranslationHelper */ private $locale; - /** - * The path to the Zend application root - * - * @var string - */ - private $appDir; - /** * The path to the module, if any * @@ -79,13 +72,6 @@ class GettextTranslationHelper */ private $moduleDir; - /** - * Path to the Icinga library - * - * @var string - */ - protected $libDir; - /** * The path to the file catalog * @@ -115,9 +101,7 @@ class GettextTranslationHelper */ public function __construct(ApplicationBootstrap $bootstrap, $locale) { - $this->moduleMgr = $bootstrap->getModuleManager()->loadEnabledModules(); - $this->appDir = $bootstrap->getApplicationDir(); - $this->libDir = $bootstrap->getLibraryDir('Icinga'); + $this->moduleMgr = $bootstrap->getModuleManager(); $this->locale = $locale; } @@ -158,32 +142,6 @@ class GettextTranslationHelper return $this; } - /** - * Update the translation table for the main application - */ - public function updateIcingaTranslations() - { - $this->catalogPath = tempnam(sys_get_temp_dir(), 'IcingaTranslation_'); - $this->templatePath = tempnam(sys_get_temp_dir(), 'IcingaPot_'); - $this->version = 'None'; // TODO: Access icinga version from a file or property - - $this->moduleDir = null; - $this->tablePath = implode( - DIRECTORY_SEPARATOR, - array( - $this->appDir, - 'locale', - $this->locale, - 'LC_MESSAGES', - 'icinga.po' - ) - ); - - $this->createFileCatalog(); - $this->createTemplateFile(); - $this->updateTranslationTable(); - } - /** * Update the translation table for a particular module * @@ -214,25 +172,6 @@ class GettextTranslationHelper $this->updateTranslationTable(); } - /** - * Compile the translation table for the main application - */ - public function compileIcingaTranslation() - { - $this->tablePath = implode( - DIRECTORY_SEPARATOR, - array( - $this->appDir, - 'locale', - $this->locale, - 'LC_MESSAGES', - 'icinga.po' - ) - ); - - $this->compileTranslationTable(); - } - /** * Compile the translation table for a particular module * @@ -326,15 +265,15 @@ class GettextTranslationHelper private function updateHeader($path) { $headerInfo = array( - 'title' => 'Icinga Web 2 - Head for multiple monitoring backends', - 'copyright_holder' => 'Icinga Development Team', + 'title' => $this->moduleMgr->getModule($this->moduleName)->getTitle(), + 'copyright_holder' => 'TEAM NAME', 'copyright_year' => date('Y'), 'author_name' => 'FIRST AUTHOR', 'author_mail' => 'EMAIL@ADDRESS', 'author_year' => 'YEAR', - 'project_name' => $this->moduleName ? ucfirst($this->moduleName) . ' Module' : 'Icinga Web 2', + 'project_name' => ucfirst($this->moduleName) . ' Module', 'project_version' => $this->version, - 'project_bug_mail' => 'dev@icinga.com', + 'project_bug_mail' => 'ISSUE TRACKER', 'pot_creation_date' => date('Y-m-d H:iO'), 'po_revision_date' => 'YEAR-MO-DA HO:MI+ZONE', 'translator_name' => 'FULL NAME', @@ -418,7 +357,7 @@ class GettextTranslationHelper { shell_exec(sprintf( "sed -i 's;%s;../../../..;g' %s", - $this->moduleDir ?: dirname($this->appDir), + $this->moduleDir, $path )); } @@ -433,12 +372,7 @@ class GettextTranslationHelper $catalog = new File($this->catalogPath, 'w'); try { - if ($this->moduleDir) { - $this->getSourceFileNames($this->moduleDir, $catalog); - } else { - $this->getSourceFileNames($this->appDir, $catalog); - $this->getSourceFileNames($this->libDir, $catalog); - } + $this->getSourceFileNames($this->moduleDir, $catalog); } catch (Exception $error) { throw $error; } diff --git a/modules/translation/module.info b/modules/translation/module.info index 196c63dce..8dc9467a4 100644 --- a/modules/translation/module.info +++ b/modules/translation/module.info @@ -1,7 +1,7 @@ Module: translation Version: 2.8.2 Description: Translation module - This module allows developers and translators to translate Icinga Web 2 and - its modules for multiple languages. You do not need this module to run an - internationalized web frontend. This is only for people who want to contribute - translations or translate just their own modules. + This module allows developers and translators to translate modules for multiple + languages. You do not need this module to run an internationalized web frontend. + This is only for people who want to contribute translations or translate just + their own modules.