I created a special validator expanding Zend_Validate_Abstractto check the CAPTCHA input against Zend_Captcha:
class My_Validate_Captcha extends Zend_Validate_Abstract {
const CAPTCHA = 'captcha';
protected $_messageTemplates = array(
self::CAPTCHA => "'%value%' isn't the right solution"
);
protected $_id;
public function __construct($captchaId) {
$this->setId($captchaId);
}
public function setId($id) {
$this->_id = $id;
return $this;
}
public function getId() {
return $this->_id;
}
public function isValid($value) {
$this->_setValue($value);
$captcha = new Zend_Captcha_Image();
if(!$captcha->isValid(array('input' => $value, 'id' => $this->getId()))) {
$this->_error(self::CAPTCHA);
return false;
}
return true;
}
}
It works great with Zend_Filter_Input. As you can see, I defined an error message for the case when the input value is invalid.
Now I tried to translate this message into German in the same way as I translated other messages from classes Zend_Validate_*. I did this with Zend_Translateproviding an array adapter.
return array(
'notAlnum' => "'%value%' darf nur Buchstaben und Zahlen enthalten",
'stringEmpty' => "'%value%' Dieser Wert darf nicht leer sein",
'captcha' => "'%value%' ist nicht die richtige Lösung"
)
, Zend_Validate_* , , My_Validate_Captcha . , 'captcha' . , , .
, ?