ZF-2734: Improvements for Zend_Validate_EmailAddress and Zend_Validate_HostName Integration

Description

It should be desirable that Zend_Validate_EmailAddress could propagate his current translator to the Zend_Validate_HostName prior validating it.

Also, Zend_Validate_HostName messages aren't returned with the corresponding keys, making them impossible to translate through a Zend_Form object.

I suggest change this code at Zend/Validate/EmailAddress.php from:


// Match hostname part
$hostnameResult = $this->hostnameValidator->isValid($this->_hostname);
if (!$hostnameResult) {
    $this->_error(self::INVALID_HOSTNAME);
    foreach ($this->hostnameValidator->getMessages() as $message) {
         $this->_messages[] = $message;
    }
    foreach ($this->hostnameValidator->getErrors() as $error) {
         $this->_errors[] = $error;
    }
}

To:


// Propagate current translator to the hostname validator
$this->hostnameValidator->setTranslator($this->getTranslator());
// Match hostname part
$hostnameResult = $this->hostnameValidator->isValid($this->_hostname);
if (!$hostnameResult) {
      $this->_error(self::INVALID_HOSTNAME);
       foreach ($this->hostnameValidator->getMessages() as $key=>$message) {
            $this->_messages[$key] = $message;
       }
       foreach ($this->hostnameValidator->getErrors() as $error) {
            $this->_errors[] = $error;
       }
}

Comments

Not a Zend_Form issue; this has to do with Zend_Validate. Assigning to Darby.

BTW, you can set a global translator for Validate objects using:


Zend_Validate_Abstract::setDefaultTranslator($translate);

which will correct the problem for you in the short-term.

Already fixed in actual release. The translator is used visa-versa.