Index: HeadTitle.php =================================================================== --- HeadTitle.php (revision 9303) +++ HeadTitle.php (working copy) @@ -38,6 +38,19 @@ * @var string */ protected $_regKey = 'Zend_View_Helper_HeadTitle'; + + /** + * Whether or not auto-translation is enabled + * @var boolean + */ + protected $_translate = false; + + /** + * Translation object + * + * @var Zend_Translate_Adapter + */ + protected $_translator; /** * Retrieve placeholder for title element and optionally set state @@ -61,22 +74,90 @@ return $this; } + + /** + * Sets a translation Adapter for translation + * + * @param Zend_Translate|Zend_Translate_Adapter $translate + * @return Zend_View_Helper_HeadTitle + */ + public function setTranslator($translate) + { + if ($translate instanceof Zend_Translate_Adapter) { + $this->_translator = $translate; + } elseif ($translate instanceof Zend_Translate) { + $this->_translator = $translate->getAdapter(); + } else { + require_once 'Zend/View/Exception.php'; + throw new Zend_View_Exception("You must set an instance of Zend_Translate or Zend_Translate_Adapter"); + } + return $this; + } /** + * Retrieve translation object + * + * If none is currently registered, attempts to pull it from the registry + * using the key 'Zend_Translate'. + * + * @return Zend_Translate_Adapter|null + */ + public function getTranslator() + { + if (null === $this->_translator) { + require_once 'Zend/Registry.php'; + if (Zend_Registry::isRegistered('Zend_Translate')) { + $this->setTranslator(Zend_Registry::get('Zend_Translate')); + } + } + return $this->_translator; + } + + /** + * Enables translation + * + * @return Zend_View_Helper_HeadTitle + */ + public function enableTranslation() + { + $this->_translate = true; + return $this; + } + + /** + * Disables translation + * + * @return Zend_View_Helper_HeadTitle + */ + public function disableTranslation() + { + $this->_translate = false; + return $this; + } + + /** * Turn helper into string * - * @param string|null $indent + * @param string|null $indent + * @param string|null $locale * @return string */ - public function toString($indent = null) + public function toString($indent = null, $locale = null) { $indent = (null !== $indent) ? $this->getWhitespace($indent) : $this->getIndent(); $items = array(); - foreach ($this as $item) { - $items[] = $this->_escape($item); + + if($this->_translate && $translator = $this->getTranslator()) { + foreach ($this as $item) { + $items[] = $this->_escape($translator->translate($item, $locale)); + } + } else { + foreach ($this as $item) { + $items[] = $this->_escape($item); + } } $separator = $this->_escape($this->getSeparator());