translation: Only allow to generate module locales

This commit is contained in:
Johannes Meyer 2021-05-28 13:55:03 +02:00
parent dcb619e62a
commit 8fe282b9aa
5 changed files with 27 additions and 148 deletions

View File

@ -4,48 +4,21 @@
namespace Icinga\Module\Translation\Clicommands; namespace Icinga\Module\Translation\Clicommands;
use Icinga\Module\Translation\Cli\TranslationCommand; use Icinga\Module\Translation\Cli\TranslationCommand;
use Icinga\Module\Translation\Util\GettextTranslationHelper;
/** /**
* Translation compiler * Translation compiler
* *
* This command will compile the PO-file of a domain. The actions below allow * This command will compile gettext catalogs of modules.
* you to select a particular domain for which the PO-file should be compiled.
* *
* Domains are the global one 'icinga' and all available and enabled modules * Once a catalog is compiled its content is used by Icinga Web 2 to display
* identified by their name.
*
* Once a PO-file is compiled its content is used by Icinga Web 2 to display
* messages in the configured language. * messages in the configured language.
*/ */
class CompileCommand extends TranslationCommand class CompileCommand extends TranslationCommand
{ {
/** /**
* Compile the global domain * Compile a module gettext catalog
* *
* This will compile the PO-file of the global 'icinga' domain. * This will compile the catalog of the given module and locale.
*
* USAGE:
*
* icingacli translation compile icinga <locale>
*
* 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.
* *
* USAGE: * USAGE:
* *
@ -53,8 +26,8 @@ class CompileCommand extends TranslationCommand
* *
* EXAMPLES: * EXAMPLES:
* *
* icingacli translation compile monitoring de_DE * icingacli translation compile demo de_DE
* icingacli trnslations compile monitoring de_DE * icingacli translation compile demo fr_FR
*/ */
public function moduleAction() public function moduleAction()
{ {

View File

@ -4,48 +4,21 @@
namespace Icinga\Module\Translation\Clicommands; namespace Icinga\Module\Translation\Clicommands;
use Icinga\Module\Translation\Cli\TranslationCommand; use Icinga\Module\Translation\Cli\TranslationCommand;
use Icinga\Module\Translation\Util\GettextTranslationHelper;
/** /**
* Translation updater * Translation updater
* *
* This command will create a new or update any existing PO-file of a domain. The * This command will create a new or update any existing gettext catalog of a module.
* actions below allow to select a particular domain for whom to touch the PO-file.
* *
* Domains are the global one 'icinga' and all available and enabled modules * Once a catalog has been created/updated one can open it with a editor for
* identified by their name.
*
* Once a PO-file has been created/updated one can open it with a editor for
* PO-files and start with the actual translation. * PO-files and start with the actual translation.
*/ */
class RefreshCommand extends TranslationCommand 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. * This will create/update the PO-file of the given module and locale.
*
* USAGE:
*
* icingacli translation refresh icinga <locale>
*
* 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.
* *
* USAGE: * USAGE:
* *
@ -53,8 +26,8 @@ class RefreshCommand extends TranslationCommand
* *
* EXAMPLES: * EXAMPLES:
* *
* icingacli translation refresh module monitoring de_DE * icingacli translation refresh module demo de_DE
* icingacli translation refresh module monitoring fr_FR * icingacli translation refresh module demo fr_FR
*/ */
public function moduleAction() public function moduleAction()
{ {

View File

@ -1,13 +1,12 @@
# Introduction <a id="module-translation-introduction"></a> # Introduction <a id="module-translation-introduction"></a>
Icinga Web 2 provides localization out of the box - for the core application and the modules, that means Icinga Web 2 provides localization out of the box - for itself and the core modules.
that you can with a lightness use existent localizations, update or even create you own localizations. 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), The chapters [Translation for Developers](03-Translation.md#module-translation-developers),
[Translation for Translators](03-Translation.md#module-translation-translators) and [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 [Testing Translations](03-Translation.md#module-translation-tests) will introduce and
part on localizing Icinga Web 2 for different languages and how to use the explain you, how to take part on localizing modules to different languages.
`translation module` to make your life much easier.
## Translation for Developers <a id="module-translation-developers"></a> ## Translation for Developers <a id="module-translation-developers"></a>

View File

@ -65,13 +65,6 @@ class GettextTranslationHelper
*/ */
private $locale; private $locale;
/**
* The path to the Zend application root
*
* @var string
*/
private $appDir;
/** /**
* The path to the module, if any * The path to the module, if any
* *
@ -79,13 +72,6 @@ class GettextTranslationHelper
*/ */
private $moduleDir; private $moduleDir;
/**
* Path to the Icinga library
*
* @var string
*/
protected $libDir;
/** /**
* The path to the file catalog * The path to the file catalog
* *
@ -115,9 +101,7 @@ class GettextTranslationHelper
*/ */
public function __construct(ApplicationBootstrap $bootstrap, $locale) public function __construct(ApplicationBootstrap $bootstrap, $locale)
{ {
$this->moduleMgr = $bootstrap->getModuleManager()->loadEnabledModules(); $this->moduleMgr = $bootstrap->getModuleManager();
$this->appDir = $bootstrap->getApplicationDir();
$this->libDir = $bootstrap->getLibraryDir('Icinga');
$this->locale = $locale; $this->locale = $locale;
} }
@ -158,32 +142,6 @@ class GettextTranslationHelper
return $this; 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 * Update the translation table for a particular module
* *
@ -214,25 +172,6 @@ class GettextTranslationHelper
$this->updateTranslationTable(); $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 * Compile the translation table for a particular module
* *
@ -326,15 +265,15 @@ class GettextTranslationHelper
private function updateHeader($path) private function updateHeader($path)
{ {
$headerInfo = array( $headerInfo = array(
'title' => 'Icinga Web 2 - Head for multiple monitoring backends', 'title' => $this->moduleMgr->getModule($this->moduleName)->getTitle(),
'copyright_holder' => 'Icinga Development Team', 'copyright_holder' => 'TEAM NAME',
'copyright_year' => date('Y'), 'copyright_year' => date('Y'),
'author_name' => 'FIRST AUTHOR', 'author_name' => 'FIRST AUTHOR',
'author_mail' => 'EMAIL@ADDRESS', 'author_mail' => 'EMAIL@ADDRESS',
'author_year' => 'YEAR', '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_version' => $this->version,
'project_bug_mail' => 'dev@icinga.com', 'project_bug_mail' => 'ISSUE TRACKER',
'pot_creation_date' => date('Y-m-d H:iO'), 'pot_creation_date' => date('Y-m-d H:iO'),
'po_revision_date' => 'YEAR-MO-DA HO:MI+ZONE', 'po_revision_date' => 'YEAR-MO-DA HO:MI+ZONE',
'translator_name' => 'FULL NAME', 'translator_name' => 'FULL NAME',
@ -418,7 +357,7 @@ class GettextTranslationHelper
{ {
shell_exec(sprintf( shell_exec(sprintf(
"sed -i 's;%s;../../../..;g' %s", "sed -i 's;%s;../../../..;g' %s",
$this->moduleDir ?: dirname($this->appDir), $this->moduleDir,
$path $path
)); ));
} }
@ -433,12 +372,7 @@ class GettextTranslationHelper
$catalog = new File($this->catalogPath, 'w'); $catalog = new File($this->catalogPath, 'w');
try { try {
if ($this->moduleDir) {
$this->getSourceFileNames($this->moduleDir, $catalog); $this->getSourceFileNames($this->moduleDir, $catalog);
} else {
$this->getSourceFileNames($this->appDir, $catalog);
$this->getSourceFileNames($this->libDir, $catalog);
}
} catch (Exception $error) { } catch (Exception $error) {
throw $error; throw $error;
} }

View File

@ -1,7 +1,7 @@
Module: translation Module: translation
Version: 2.8.2 Version: 2.8.2
Description: Translation module Description: Translation module
This module allows developers and translators to translate Icinga Web 2 and This module allows developers and translators to translate modules for multiple
its modules for multiple languages. You do not need this module to run an languages. You do not need this module to run an internationalized web frontend.
internationalized web frontend. This is only for people who want to contribute This is only for people who want to contribute translations or translate just
translations or translate just their own modules. their own modules.