How could we create a translation to validate error messages in the zend framework?
From ZF Manual Zend_Validate
to Verification Messages
$validator = new Zend_Validate_GreaterThan();
$validator->setMessage('Please enter a lower value',
Zend_Validate_GreaterThan::NOT_GREATER);
And:
Zend Framework comes with over 45 different validators with over 200 error messages. It can be challenging to translate all of these messages. But for your convenience, Zend Framework comes with pre-translated validation messages. You can find them along the way
/resources/languages
in your Zend Framework installation. [...]
Therefore, to translate all validation messages into German, all you have to do is attach the translator toZend_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 make them available to the translation adapter. Basically, you just swap the part shown above for your own path.
a source to share
I just want to improve a little on the answer from Gordon: working example
$translator = new Zend_Translate(
'array',
'resources/languages', // you need to copy the resources folder
// (from your Zend Framework installation)
// in the application folder
'it', // 'it' for italian, 'fr' for french, etc.
// Just look at the directories
// Zend_Translate, NOT Zend_Locale
array(
'scan' => Zend_Translate::LOCALE_DIRECTORY
)
);
Zend_Validate_Abstract::setDefaultTranslator($translator);
Hooray! Bruno
a source to share