views:

91

answers:

1

Hello, assume this situation

$form->addElement('select', 'companies', array(
  'disableTranslator' => true,
  'label'             => Zend_Registry::get('Zend_Translate')->_('companies'),
  'filters'           => array('Int'),
  'required'          => true,
  'multiOptions'      => array(1 => 'Company 1', 2 => 'Company 2')
));

if($_POST && $form->isValid($_POST)) {
  $form->save();
}

$form->render();

This select serves to select companies from a given list of options.
The form has a default translator set with 1 translated phrase "my_translated_text" => "here comes the translation".

The options in select box are populated based on data entered by users which means users may add a company with name my_translated_text which in turn should appear as new option in the select box saying "my_translated_text".

If there was no disableTranslator => true option, the my_translated_text company would be translated to here comes the translation and thus appear as translated text -> we need to disable translations.

But if there's disableTranslator => true the error messages (such as "The value is required") are not translated.

Ideally I don't want to translate the values, but want to translate everything else regarding the select box.
How do you deal with such situation? Have you ever had similar problem?

Thank you

+1  A: 

I have some trouble understand the question, but if I understand correctly, you do not want the option values translated. There is no way to do this from Zend_Form. Like you said, you can only en/disable the translator for the entire element.

Your best bet would be to create a custom Form Element or Decorator. I am not entirely sure where the translations take place, but I think the options are already translated in Zend_Form_Multi's _translateValue() method. Another class to look at would the View Helper rendering the Select Box.


On a sidenote: when there is a default translator set, you should not need to do

'label' => Zend_Registry::get('Zend_Translate')->_('companies')

because labels are translated by default. And even if you had to do this, the translator is better retrieved by Zend_Form::getTranslator() instead of via Zend_Registry to avoid coupling.

Gordon