ZF-3173: Integrate Zend_Translate with Zend_View_Helper_HeadTitle?
Description
It seemed to make sense to me that the HeadTitle helper should be doing translation when it's cast to string, and it was pretty trivial to implement. Thoughts?
Index: HeadTitle.php
===================================================================
--- HeadTitle.php (revision 9303)
+++ HeadTitle.php (working copy)
@@ -19,6 +19,9 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
+/** Zend_Registry */
+require_once 'Zend/Registry.php';
+
/** Zend_View_Helper_Placeholder_Container_Standalone */
require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';
@@ -65,18 +68,28 @@
/**
* 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(Zend_Registry::isRegistered('Zend_Translate')) {
+ $translator = Zend_Registry::get('Zend_Translate');
+
+ 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());
Comments
Posted by Matthew Weier O'Phinney (matthew) on 2008-04-25T06:59:04.000+0000
I can see a benefit to this, definitely. However, I can also see this leading to unexpected results when people are unaware that it translates.
I think a better solution would be to have an accessor via which you can enable or disable translation:
I'm going to schedule this for the next minor release.
Posted by C Snover (snover) on 2008-04-26T01:41:07.000+0000
Here's a patch that should be doing things more properly. Sorry about the lazy patch before, I am a lazy lazy man. :) One last thing I am wondering... would it be possible (or wise) to try pulling the translator from a registered Zend_View_Helper_Translate object in addition to the Zend_Registry key?
Posted by C Snover (snover) on 2008-04-26T01:49:02.000+0000
(Replacement patch) Or, we could try not requiring Zend/Registry.php twice. Sigh. Sloppy copy & paste on my part.
Posted by Thomas Weidner (thomas) on 2008-05-02T12:57:24.000+0000
No this would not be wise, because the official registry key to use for the translation adapter within all other components is "Zend_Translate"... ;-) See the Zend_View_Helper_Translate helper for details.
Posted by Matthew Weier O'Phinney (matthew) on 2008-10-29T06:17:30.000+0000
Assigning to Jon W.
Posted by Jon Whitcraft (sidhighwind) on 2008-11-10T18:07:18.000+0000
This was done with r12537
Posted by Wil Sinclair (wil) on 2008-11-13T14:10:09.000+0000
Changing issues in preparation for the 1.7.0 release.