diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php index 7699c76bd..195376f1c 100644 --- a/library/Icinga/Application/Modules/Module.php +++ b/library/Icinga/Application/Modules/Module.php @@ -17,6 +17,7 @@ use Icinga\Web\Navigation\Navigation; use Icinga\Web\Widget; use ipl\I18n\GettextTranslator; use ipl\I18n\StaticTranslator; +use ipl\I18n\Translation; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; use Zend_Controller_Router_Route; @@ -30,6 +31,11 @@ use Zend_Controller_Router_Route_Regex; */ class Module { + use Translation { + translate as protected; + translatePlural as protected; + } + /** * Module name * @@ -301,6 +307,8 @@ class Module $this->runScript = $basedir . '/run.php'; $this->configScript = $basedir . '/configuration.php'; $this->metadataFile = $basedir . '/module.info'; + + $this->translationDomain = $name; } /** @@ -1635,22 +1643,4 @@ class Module $this->routes[$name] = $route; return $this; } - - /** - * (non-PHPDoc) - * @see Translator::translate() For the function documentation. - */ - protected function translate($string, $context = null) - { - return mt($this->name, $string, $context); - } - - /** - * (non-PHPDoc) - * @see Translator::translatePlural() For the function documentation. - */ - protected function translatePlural($textSingular, $textPlural, $number, $context = null) - { - return mtp($this->name, $textSingular, $textPlural, $number, $context); - } } diff --git a/library/Icinga/Cli/Command.php b/library/Icinga/Cli/Command.php index 0f15bdb75..d1a19862a 100644 --- a/library/Icinga/Cli/Command.php +++ b/library/Icinga/Cli/Command.php @@ -8,10 +8,12 @@ use Icinga\Application\Config; use Icinga\Application\Logger; use Icinga\Exception\IcingaException; use Icinga\Exception\NotReadableError; -use Icinga\Util\Translator; +use ipl\I18n\Translation; abstract class Command { + use Translation; + protected $app; protected $docs; @@ -61,6 +63,8 @@ abstract class Command $this->isDebugging = $this->params->shift('debug', false); $this->configs = []; + $this->translationDomain = $moduleName ?: 'icinga'; + if ($this->loadEnabledModules) { try { $app->getModuleManager()->loadEnabledModules(); @@ -134,21 +138,6 @@ abstract class Command return $this->trace; } - /** - * Translate a string - * - * Autoselects the module domain, if any, and falls back to the global one if no translation could be found. - * - * @param string $text The string to translate - * - * @return string The translated string - */ - public function translate($text) - { - $domain = $this->moduleName === null ? 'icinga' : $this->moduleName; - return Translator::translate($text, $domain); - } - public function fail($msg) { throw new IcingaException('%s', $msg); diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index 4ec2ddebb..434e07f8b 100644 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -3,6 +3,7 @@ namespace Icinga\Web\Controller; +use ipl\I18n\Translation; use Zend_Controller_Action; use Zend_Controller_Action_HelperBroker; use Zend_Controller_Request_Abstract; @@ -16,7 +17,6 @@ use Icinga\Exception\ProgrammingError; use Icinga\File\Pdf; use Icinga\Forms\AutoRefreshForm; use Icinga\Security\SecurityException; -use Icinga\Util\Translator; use Icinga\Web\Session; use Icinga\Web\Url; use Icinga\Web\UrlParams; @@ -40,6 +40,8 @@ use Icinga\Web\Window; */ class ActionController extends Zend_Controller_Action { + use Translation; + /** * The login route to use when requiring authentication */ @@ -131,7 +133,8 @@ class ActionController extends Zend_Controller_Action $moduleName = $this->getModuleName(); $this->view->defaultTitle = static::DEFAULT_TITLE; - $this->view->translationDomain = $moduleName !== 'default' ? $moduleName : 'icinga'; + $this->translationDomain = $moduleName !== 'default' ? $moduleName : 'icinga'; + $this->view->translationDomain = $this->translationDomain; $this->_helper->layout()->isIframe = $request->getUrl()->shift('isIframe'); $this->_helper->layout()->showFullscreen = $request->getUrl()->shift('showFullscreen'); $this->_helper->layout()->moduleName = $moduleName; @@ -305,42 +308,6 @@ class ActionController extends Zend_Controller_Action return $this->view->tabs; } - /** - * Translate a string - * - * Autoselects the module domain, if any, and falls back to the global one if no translation could be found. - * - * @param string $text The string to translate - * @param string|null $context Optional parameter for context based translation - * - * @return string The translated string - */ - public function translate($text, $context = null) - { - return Translator::translate($text, $this->view->translationDomain, $context); - } - - /** - * Translate a plural string - * - * @param string $textSingular The string in singular form to translate - * @param string $textPlural The string in plural form to translate - * @param string $number The number to get the plural or singular string - * @param string|null $context Optional parameter for context based translation - * - * @return string The translated string - */ - public function translatePlural($textSingular, $textPlural, $number, $context = null) - { - return Translator::translatePlural( - $textSingular, - $textPlural, - $number, - $this->view->translationDomain, - $context - ); - } - protected function ignoreXhrBody() { if ($this->isXhr()) { diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index f836d0f78..bc7f44457 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -4,6 +4,7 @@ namespace Icinga\Web; use Icinga\Web\Form\Element\DateTimePicker; +use ipl\I18n\Translation; use Zend_Config; use Zend_Form; use Zend_Form_Element; @@ -12,7 +13,6 @@ use Icinga\Application\Icinga; use Icinga\Authentication\Auth; use Icinga\Exception\ProgrammingError; use Icinga\Security\SecurityException; -use Icinga\Util\Translator; use Icinga\Web\Form\ErrorLabeller; use Icinga\Web\Form\Decorator\Autosubmit; use Icinga\Web\Form\Element\CsrfCounterMeasure; @@ -27,6 +27,11 @@ use Icinga\Web\Form\Element\CsrfCounterMeasure; */ class Form extends Zend_Form { + use Translation { + translate as i18nTranslate; + translatePlural as i18nTranslatePlural; + } + /** * The suffix to append to a field's hidden default field name */ @@ -1519,7 +1524,9 @@ class Form extends Zend_Form */ protected function translate($text, $context = null) { - return Translator::translate($text, $this->getTranslationDomain(), $context); + $this->translationDomain = $this->getTranslationDomain(); + + return $this->i18nTranslate($text, $context); } /** @@ -1534,13 +1541,9 @@ class Form extends Zend_Form */ protected function translatePlural($textSingular, $textPlural, $number, $context = null) { - return Translator::translatePlural( - $textSingular, - $textPlural, - $number, - $this->getTranslationDomain(), - $context - ); + $this->translationDomain = $this->getTranslationDomain(); + + return $this->i18nTranslatePlural($textSingular, $textPlural, $number, $context); } /** diff --git a/library/Icinga/Web/View.php b/library/Icinga/Web/View.php index 55ee4543b..bdc7b6d6b 100644 --- a/library/Icinga/Web/View.php +++ b/library/Icinga/Web/View.php @@ -5,10 +5,10 @@ namespace Icinga\Web; use Closure; use Icinga\Application\Icinga; +use ipl\I18n\Translation; use Zend_View_Abstract; use Icinga\Authentication\Auth; use Icinga\Exception\ProgrammingError; -use Icinga\Util\Translator; /** * Icinga view @@ -54,6 +54,8 @@ use Icinga\Util\Translator; */ class View extends Zend_View_Abstract { + use Translation; + /** * Charset to be used - we only support UTF-8 */ @@ -178,21 +180,6 @@ class View extends Zend_View_Abstract ); } - public function translate($text, $context = null) - { - return Translator::translate($text, $this->translationDomain, $context); - } - - /** - * Translate a plural string - * - * @see Translator::translatePlural() - */ - public function translatePlural($textSingular, $textPlural, $number, $context = null) - { - return Translator::translatePlural($textSingular, $textPlural, $number, $this->translationDomain, $context); - } - /** * Load helpers */