Hi fellow hackers!
I'm writing an application using the Zend_Filter_Input class for
filtering and validation. My app is multilingual and I have an instance
of Zend_Translate up and running.
The only problem is, that I'd like to translate the error messages, or
better said the message templates, used by the Zend_Validate_* classes.
Let's say I want to validate a value 'abc$123' with the
Zend_Validate_Alnum validator. This would give me the message
"'abc$123' has not only alphabetic and digit characters"
Of course this is in english language, because that's how the message
template is defined.
Also at this point the placeholder %value% in the message template is
already substituted by the value to check, so if I wanted to translate
this message I'd first have to extract the value from the error message,
translate the message and replace the value again, which leads to
extreme regex (or str_replace for all you performance junkies ;-)) madness.
Now what I'd like to do is, before using the validator, get all message
templates, run them through the translator and use the translated
templates instead.
Something like
foreach ($validator->_messageTemplates as $k => $v) {
$validator->_messageTemplates[$k] = $translator->_($v);
}
Sadly the message templates are hideden in a protected property and
there seems to be no get method or something, so there's no way to
change them from the outside :-(
The only ideas I came up with so far would be
a) patch the ZF sources -> bad idea!
b) Subclass each validator and add a get/setMessageTemplates method ->
too complicated
Any help on this topic would be greatly appreciated,
cheers
Sascha
--
View this message in context:
http://www.nabble.com/Zend_Validate---translate-message-templates-tf4772695s16154.html#a13652812
Sent from the Zend Framework mailing list archive at Nabble.com.