ZF-12090: Zend Form is not translating placeholders

Description

Zend Form is not translating placeholders

Comments

Yes the html5 attribute, i was looking, but it seems that it only happends when you use an ini file. Because if you are using a php you could set the translation once you assign the value. But I'm assigning it through the ini file using a key like 'section.name.error', I guess it treats all the attributes the same way. And doesn't take into account that that kind of attribut should be translated. I dont know if the solution would be adding a specific way to declare the placeholders in the ini when the form reads it, or allow ini files to run functions/methods on the assigned values.

May be the method Zend_Form_Element::setAttrib could take into account that kind of stuff:


public function setAttrib($name, $value)
{
    $name = (string) $name;
    if ('_' == $name[0]) {
        require_once 'Zend/Form/Exception.php';
        throw new Zend_Form_Exception(sprintf('Invalid attribute "%s"; must not contain a leading underscore', $name));
    }

    if (null === $value) {
        unset($this->$name);
    } else {
        $this->$name = $value;
    }

    return $this;
}

A simple solution would be:


public function setAttrib($name, $value)
{
    $name = (string) $name;
    if ('_' == $name[0]) {
        require_once 'Zend/Form/Exception.php';
        throw new Zend_Form_Exception(sprintf('Invalid attribute "%s"; must not contain a leading underscore', $name));
    }

    if (null === $value) {
        unset($this->$name);
    } else {
=====================================================================================
        if ($this->getView()->doctype()->isHtml5() && $name === 'placeholder') {
            $value = $view->translate($value);
        }
=====================================================================================
        $this->$name = $value;
    }

    return $this;
}

Hi Ricardo, {{Zend_Form_Element}} has his own translator: Zend_Form_Element::getTranslator()

Maybe a new decorator is an option, similar to Zend_Form_Decorator_Tooltip.

A placeholder is an special property as could be title and alt, those properties should be translated without any other decoration or specification. I think it should be transparent to code using the library.

The best solution would be to move the translation into the view layer, but in ZF1 it is inconsistent to label, description, … But it is also a bad idea to check the doctype in Zend_Form!