2

When setting the title attribute in Zend_Form, this is not being translated. (Label & errors are translated fine)

// form file

$email = new Zend_Form_Element_Text('username');
$email->setLabel('auth.form.login.username')
      ->setRequired(true)
      ->addFilter('StripTags')
      ->addFilter('StringTrim')
      ->addFilter('StringToLower')
      ->addValidator('NotEmpty')
      ->setAttrib('title', 'auth.form.login.username');

// resource file

...
<tu tuid='auth.form.login.username'>
   <tuv xml:lang="en"><seg>Username</seg></tuv>
</tu>
...

Current result: auth.form.login.username

Expected result: Username

Liyali
  • 5,643
  • 2
  • 26
  • 40
Eddie Jaoude
  • 1,698
  • 15
  • 23
  • I can't remember that the attribute setter did translate. Looks like your expectation is wrong. Instead set the translated value. – hakre Apr 04 '12 at 16:15

1 Answers1

1

This is a normal behavior, nothing wrong with it.

The setAttrib() method doesn't translate its value parameter, so you need to use a Zend_Translate adapter as follows:

$email->setAttrib('title', $this->getTranslator()->translate('auth.form.login.username'))

This should fix your problem.

See Standard I18n Targets for more information.

Now that you've attached a translation object to, what exactly can you translate by default?

  • Validation error messages.
  • Labels.
  • Fieldset Legends.
  • Form and Element Descriptions.
  • Multi-option Values.
  • Submit and Button Labels.
Liyali
  • 5,643
  • 2
  • 26
  • 40