diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php index 6d66412e6..6cbb49a9b 100644 --- a/library/Icinga/Application/Modules/Module.php +++ b/library/Icinga/Application/Modules/Module.php @@ -924,4 +924,9 @@ class Module { return mt($this->name, $string); } + + protected function translatePlural($string, $string2, $n) + { + return mtp($this->name, $string, $string2, $n); + } } diff --git a/library/Icinga/Application/functions.php b/library/Icinga/Application/functions.php index 422dfeab7..42f35747f 100644 --- a/library/Icinga/Application/functions.php +++ b/library/Icinga/Application/functions.php @@ -14,6 +14,10 @@ if (extension_loaded('gettext')) { { return Translator::translate($messageId, $domain); } + function mtp($domain, $messageId, $messageId2, $n) + { + return Translator::translatePlural($messageId, $messageId2, $n, $domain); + } } else { function t($messageId) { diff --git a/library/Icinga/Util/Translator.php b/library/Icinga/Util/Translator.php index b6cf533d9..df246f580 100644 --- a/library/Icinga/Util/Translator.php +++ b/library/Icinga/Util/Translator.php @@ -48,6 +48,12 @@ class Translator return $res; } + public static function translatePlural($msgid1, $msgid2, $n, $domain) + { + $res = dngettext($domain, $msgid1, $msgid2, $n); + return $res; + } + /** * Register a new gettext domain * diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index aead4043a..7b0a267ee 100644 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -225,6 +225,20 @@ class ActionController extends Zend_Controller_Action return Translator::translate($text, $this->view->translationDomain); } + /** + * Translate a plural string + * + * @param $msgid1 + * @param $msgid2 + * @param $n + * + * @return string + */ + public function translatePlural($msgid1, $msgid2, $n) + { + return Translator::translatePlural($msgid1, $msgid2, $n, $this->view->translationDomain); + } + protected function ignoreXhrBody() { if ($this->isXhr()) { diff --git a/library/Icinga/Web/View.php b/library/Icinga/Web/View.php index 22e8e6fbd..467ab9671 100644 --- a/library/Icinga/Web/View.php +++ b/library/Icinga/Web/View.php @@ -132,6 +132,11 @@ class View extends Zend_View_Abstract return Translator::translate($text, $this->translationDomain); } + public function translatePlural($text, $text2, $n) + { + return Translator::translatePlural($text, $text2, $n, $this->translationDomain); + } + /** * Load helpers */ diff --git a/modules/translation/library/Translation/Util/GettextTranslationHelper.php b/modules/translation/library/Translation/Util/GettextTranslationHelper.php index 9d72b9c77..82560aeb4 100644 --- a/modules/translation/library/Translation/Util/GettextTranslationHelper.php +++ b/modules/translation/library/Translation/Util/GettextTranslationHelper.php @@ -237,6 +237,7 @@ class GettextTranslationHelper '/usr/bin/xgettext', '--language=PHP', '--keyword=translate', + '--keyword=translatePlural:1,2', '--keyword=mt:2', '--keyword=t', '--sort-output',