Issues

ZF-3173: Integrate Zend_Translate with Zend_View_Helper_HeadTitle?

Issue Type: Patch Created: 2008-04-24T16:49:43.000+0000 Last Updated: 2008-11-13T14:10:09.000+0000 Status: Resolved Fix version(s): - 1.7.0 (17/Nov/08)

Reporter: C Snover (snover) Assignee: Jon Whitcraft (sidhighwind) Tags: - Zend_View

Related issues: Attachments: - HeadTitle.php.diff

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?

<pre class="highlight">
Index: HeadTitle.php
===================================================================
--- HeadTitle.php   (revision 9303)
+++ HeadTitle.php   (working copy)
@@ -19,6 +19,9 @@
  * @license    <a href="http://framework.zend.com/license/new-bsd">http://framework.zend.com/license/new-bsd</a>     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:

<pre class="highlight">
$this->headTitle()->enableTranslation();

// optionally, even set the specific translation object:
$this->headTitle()->setTranslator(...);

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.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts