zend-frameworkzend-formzend-form-elementzend-translatezend-form-select

Not translate select options in Zend Framework 1


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


Solution

  • 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.