From 360ac875503d83d696c0cc2263f6a6f49221881f Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 27 May 2014 21:41:46 +0000 Subject: [PATCH] Translation: add a module-aware translation helper With this fix $this->translate works in our view scripts refs #6338 --- library/Icinga/Web/Controller/ActionController.php | 3 +++ library/Icinga/Web/View.php | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index 889be721c..e2c514f82 100644 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -128,6 +128,9 @@ class ActionController extends Zend_Controller_Action $this->windowId = $this->_request->getHeader('X-Icinga-WindowId', null); } + $module = $request->getModuleName(); + $this->view->translationDomain = $module === 'default' ? 'icinga' : $module; + if ($this->requiresConfig() === false) { if ($this->requiresLogin() === false) { $this->view->tabs = new Tabs(); diff --git a/library/Icinga/Web/View.php b/library/Icinga/Web/View.php index 67995f8c7..ce44ea73a 100644 --- a/library/Icinga/Web/View.php +++ b/library/Icinga/Web/View.php @@ -31,6 +31,7 @@ namespace Icinga\Web; use Icinga\Exception\ProgrammingError; +use Icinga\Util\Translator; use Zend_View_Abstract; use Closure; @@ -154,6 +155,11 @@ class View extends Zend_View_Abstract ); } + public function translate($text) + { + return Translator::translate($text, $this->translationDomain); + } + /** * Load helpers */