Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

FormSelect translate optgroup label fix #4356

Closed
wants to merge 1 commit into from

2 participants

@robertboloc

Optgroup labels in FormSelect were not translated.

@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4356'
Close #4356
b3a16ad
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4356' into develop
Forward port #4356
a38e392
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 29, 2013
  1. @robertboloc
This page is out of date. Refresh to see the latest.
View
4 library/Zend/Form/View/Helper/FormSelect.php
@@ -47,6 +47,10 @@ class FormSelect extends AbstractHelper
'label' => true,
);
+ protected $translatableAttributes = array(
+ 'label' => true,
+ );
+
/**
* Render a form <select> element from the provided $element
*
View
37 tests/ZendTest/Form/View/Helper/FormSelectTest.php
@@ -239,6 +239,43 @@ public function testCanTranslateContent()
$this->assertContains('>translated content<', $markup);
}
+ public function testCanTranslateOptGroupLabel()
+ {
+ $element = new SelectElement('test');
+ $element->setValueOptions(array(
+ 'optgroup' => array(
+ 'label' => 'translate me',
+ 'options' => array(
+ '0' => 'foo',
+ '1' => 'bar',
+ ),
+ ),
+ ));
+
+ $mockTranslator = $this->getMock('Zend\I18n\Translator\Translator');
+ $mockTranslator->expects($this->at(0))
+ ->method('translate')
+ ->with('translate me')
+ ->will($this->returnValue('translated label'));
+ $mockTranslator->expects($this->at(1))
+ ->method('translate')
+ ->with('foo')
+ ->will($this->returnValue('translated foo'));
+ $mockTranslator->expects($this->at(2))
+ ->method('translate')
+ ->with('bar')
+ ->will($this->returnValue('translated bar'));
+
+ $this->helper->setTranslator($mockTranslator);
+ $this->assertTrue($this->helper->hasTranslator());
+
+ $markup = $this->helper->__invoke($element);
+
+ $this->assertContains('label="translated label"', $markup);
+ $this->assertContains('>translated foo<', $markup);
+ $this->assertContains('>translated bar<', $markup);
+ }
+
public function testTranslatorMethods()
{
$translatorMock = $this->getMock('Zend\I18n\Translator\Translator');
Something went wrong with that request. Please try again.