Hi Bryce, this looks like a promising approach and feels more natural like the array config to me. I'll definitely have a look at this soon.
Sadly it doesn't solve my problem with the message templates. Of course I could set the messages für each configuration separately, but the big picture I have in mind is to have a subclass of Zend_Filter_Input, check which validators are required and pass those validators message templates to the translator. The more I think of this, having a public method getMessageTemplates() in the Zend_Validate_Abstract class seems like the best approach to this. What do you think? What would be the recommended way to get such a change in the core? Thanks a lot in advance, Sascha Bryce Lohr schrieb: > This may or may not be helpful, but I have a class in the Laboratory > (Zend_Validate_Builder_ErrorManager) that is designed to solve just such > as use case: > http://framework.zend.com/svn/laboratory/library/Zend/Validate/Builder/ErrorManager.php > > > The only documentation I have, as of yet, is in this proposal page: > http://framework.zend.com/wiki/x/fXM > > There are a also few unit tests in the laboratory for this class as > well. If this seems like it might be useful, and you want more info, > drop me a line. > > HTH, > Bryce Lohr > > > Sascha Göbel wrote: >> 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 >> >
