Issues

ZF-2433: Add accessors to Zend_Validate_Abstract to make l10n/i18n possible

Description

Currently, it's next-to-impossible to localize validation error messages with concrete validators extending Zend_Validate_Abstract. I propose adding the following methods:


class Zend_Validate_Abstract implements Zend_Validate_Interface
{
    /**
     * Set value which caused validation failure
     */
    public function setValue($value);

    /**
     * Retrieve value causing validation failure
     */
    public function getValue();

    /**
     * Set custom template for a given validation error code
     */
    public function setMessageTemplate($code, $template);

    /**
     * Set custom templates for multiple error codes 
     * (code => template pairs)
     */
    public function setMessageTemplates(array $templates);

    /**
     * Retrieve message template for given code
     */
    public function getMessageTemplate($code);

    /**
     * Retrieve all message template (code => template pairs)
     */
    public function getMessageTemplates();

    /**
     * Set translation adapter to use when generating messages
     */
    public function setTranslator(Zend_Translate_Adapter $translator);

    /**
     * Get translation adapter
     */
    public function getTranslator();
}

Furthermore, if a translation adapter is present, validators shipped with Zend Framework should use it to translate the current message into the current locale when setting validation error messages.

These enhancements would greatly enhance validators by allowing for custom messages as well as localized messages.

Comments

Translation of validation messages has already been implemented. Resolving as Fixed for next minor release. Please reopen and/or otherwise modify if I am mistaken. :)