views:

292

answers:

1

hello

how we could create translate validate error messages on zend framework?

someone could give a example ?

thanks

+2  A: 

From the ZF Manual on Zend_Validate Validation Messages

  $validator = new Zend_Validate_GreaterThan();
  $validator->setMessage('Please enter a lower value', 
                         Zend_Validate_GreaterThan::NOT_GREATER);

And also:

Zend Framework is shipped with more than 45 different validators with more than 200 failure messages. It can be a tendious task to translate all of these messages. But for your convinience Zend Framework comes with already pre-translated validation messages. You can find them within the path /resources/languages in your Zend Framework installation. [...]
So to translate all validation messages to german for example, all you have to do is to attach a translator to Zend_Validate using these resource files.

  $translator = new Zend_Translate(
      'array',
      '/resources/languages',
      $language,
      array('scan' => Zend_Locale::LOCALE_DIRECTORY)
  );
  Zend_Validate_Abstract::setDefaultTranslator($translator);

Of course, you can also provide your own translations. All you have to do is load make them available to the translation adapter. Basically you just swap out the part shown above to your custom path.

Gordon
@Gordon Very useful, thanks a lot.
Steven Rosato