From dacbd329dd82ada10d00e757c5b6c88d923f4e32 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Mon, 29 Sep 2014 15:56:48 +0200 Subject: [PATCH 1/2] Translator: Implement domain fallback for translate and translatePlural --- library/Icinga/Util/Translator.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Util/Translator.php b/library/Icinga/Util/Translator.php index ccbdcbfcd..755203474 100644 --- a/library/Icinga/Util/Translator.php +++ b/library/Icinga/Util/Translator.php @@ -43,7 +43,11 @@ class Translator public static function translate($text, $domain, $context = null) { if ($context !== null) { - return self::pgettext($text, $domain, $context); + $res = self::pgettext($text, $domain, $context); + if ($res === $text && $domain !== self::DEFAULT_DOMAIN) { + $res = self::pgettext($text, self::DEFAULT_DOMAIN, $context); + } + return $res; } $res = dgettext($domain, $text); @@ -56,6 +60,8 @@ class Translator /** * Translate a plural string * + * Falls back to the default domain in case the string cannot be translated using the given domain + * * @param string $textSingular The string in singular form to translate * @param string $textPlural The string in plural form to translate * @param integer $number The number to get the plural or singular string @@ -67,10 +73,17 @@ class Translator public static function translatePlural($textSingular, $textPlural, $number, $domain, $context = null) { if ($context !== null) { - return self::pngettext($textSingular, $textPlural, $number, $domain, $context); + $res = self::pngettext($textSingular, $textPlural, $number, $domain, $context); + if (($res === $textSingular || $res === $textPlural) && $domain !== self::DEFAULT_DOMAIN) { + $res = self::pngettext($textSingular, $textPlural, $number, self::DEFAULT_DOMAIN, $context); + } + return $res; } $res = dngettext($domain, $textSingular, $textPlural, $number); + if (($res === $textSingular || $res === $textPlural) && $domain !== self::DEFAULT_DOMAIN) { + $res = dngettext(self::DEFAULT_DOMAIN, $textSingular, $textPlural, $number); + } return $res; } From ab8436dea81c658e4b9ca6e5dcfae3c167f41f98 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 29 Sep 2014 16:12:22 +0200 Subject: [PATCH 2/2] Fix Icinga\Web\Form\Element\Note using its default decorators --- library/Icinga/Web/Form/Element/Note.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Web/Form/Element/Note.php b/library/Icinga/Web/Form/Element/Note.php index 5788c200d..700bea107 100644 --- a/library/Icinga/Web/Form/Element/Note.php +++ b/library/Icinga/Web/Form/Element/Note.php @@ -4,13 +4,24 @@ namespace Icinga\Web\Form\Element; -use Zend_Form_Element_Xhtml; +use Zend_Form_Element; /** * Implements note element for Zend forms */ -class Note extends Zend_Form_Element_Xhtml +class Note extends Zend_Form_Element { + /** + * Disable default decorators + * + * \Icinga\Web\Form sets default decorators for elements. + * + * @var bool + * + * @see \Icinga\Web\Form::__construct() For default element decorators. + */ + protected $_disableLoadDefaultDecorators = true; + /** * Name of the view helper *