Browse Source

[ZF-6877] Zend_Form_Element:

- allow label to be translated

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18965 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 years ago
parent
commit
b5f7c53891
2 changed files with 13 additions and 0 deletions
  1. 5 0
      library/Zend/Form/Element.php
  2. 8 0
      tests/Zend/Form/ElementTest.php

+ 5 - 0
library/Zend/Form/Element.php

@@ -593,6 +593,11 @@ class Zend_Form_Element implements Zend_Validate_Interface
      */
     public function getLabel()
     {
+        $translator = $this->getTranslator();
+        if (null !== $translator) {
+            return $translator->translate($this->_label);
+        }
+
         return $this->_label;
     }
 

+ 8 - 0
tests/Zend/Form/ElementTest.php

@@ -1939,6 +1939,14 @@ class Zend_Form_ElementTest extends PHPUnit_Framework_TestCase
         $this->assertFalse($this->element->isValid('    '));
     }
 
+    public function testTranslatedLabel()
+    {
+        $this->element->setLabel('FooBar');
+        $translator = new Zend_Translate('array', array('FooBar' => 'BazBar'));
+        $this->element->setTranslator($translator);
+        $this->assertEquals('BazBar', $this->element->getLabel());
+    }
+
     // Extensions
 
     public function testInitCalledBeforeLoadDecorators()