Not translate select options in Zend Framework 1

337 Views Asked by At

I have a big form with a lot of select elements with a lot of options each one. All translations work well (labels, descriptions, errors), but i don't want to translate the options shown in the select element.

The official guide says nothing about it, please check the following link: http://framework.zend.com/manual/1.12/en/zend.form.standardElements.html#zend.form.standardElements.select

However here it says: http://framework.zend.com/manual/1.12/en/zend.form.standardElements.html#zend.form.standardElements.multiselect "If a translation adapter is registered with the form and/or element, option values will be translated for display purposes. "

I can't remove the translation adapter, so my question is: Is it possible to ignore this element options?

Looking forward to your news. BR

2

There are 2 best solutions below

1
On BEST ANSWER

The Zend_Form_Element_Multi have this:

if ($this->translatorIsDisabled()) {
    return false;
}

And there exist this method on Zend_Form_Element

public function setDisableTranslator($flag)
{
    $this->_translatorDisabled = (bool) $flag;
    return $this;
}

So I've created a method that extends Zend_Form_Element_Select and call:

$this->setDisableTranslator(true); 

That solved my question.

1
On

Add $this->setTranslator(new Zend_Translate_Adapter_Array(array())); at beginning of your form. This will override default translator, and because new one is empty then it will not translate anything.