History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: ZF-3173
Type: Patch Patch
Status: Open Open
Priority: Minor Minor
Assignee: Unassigned
Reporter: C Snover
Votes: 2
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

Integrate Zend_Translate with Zend_View_Helper_HeadTitle?

Created: 24/Apr/08 04:49 PM   Updated: 03/Sep/08 12:00 AM
Component/s: Zend_View
Affects Version/s: None
Fix Version/s: Next Minor Release

Time Tracking:
Original Estimate: 30 minutes
Original Estimate - 30 minutes
Remaining Estimate: 30 minutes
Remaining Estimate - 30 minutes
Time Spent: Not Specified
Remaining Estimate - 30 minutes

File Attachments: 1. File HeadTitle.php.diff (3 kb)
2. File HeadTitle.php.diff (4 kb)


Fix Version Priority: Should Have


 Description  « Hide
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());


 All   Comments   Work Log   Change History   FishEye   Crucible      Sort Order: Ascending order - Click to sort in descending order
Matthew Weier O'Phinney - 25/Apr/08 06:59 AM
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:

$this->headTitle()->enableTranslation();

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

I'm going to schedule this for the next minor release.


C Snover - 26/Apr/08 01:41 AM
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?

C Snover - 26/Apr/08 01:49 AM
(Replacement patch) Or, we could try not requiring Zend/Registry.php twice. Sigh. Sloppy copy & paste on my part.

Thomas Weidner - 02/May/08 12:57 PM
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.