Well, isValid adds the error message to the form as it recognises that the form or it's elements are not valid.
When you add a translation after the error has been set, then how should it be translated? That's like sending a manual to your customer and then translating it after your customer received it. Your customer will never get the translated version except you send it to him. You can translate it afterwards by creating adding translation adapter and calling isValid once again. But that's a suboptimal solution :-) It's always better to attach translations to the form as you also want to show your customer a already translated form. Thomas Weidner Zend Framework Certified Engineer & I18N Team Leader http://www.thomasweidner.com -----Ursprüngliche Nachricht----- Von: Hector Virgen [mailto:[email protected]] Gesendet: Freitag, 22. Oktober 2010 19:02 An: Zend Framework General Betreff: [fw-general] Zend_Form - Unable to translate error messages post-validation Hello, I've been following Matthew Weier O'Phinney's blog post Using Zend_Form In Your Models<http://weierophinney.net/matthew/archives/200-Using-Zend_Form-in-Your -Models.html>and so far it has been working great -- except for translation. We are currently not using Zend_Translate -- our solution is to use a view helper to apply the translated labels, descriptions etc to the form just prior to rendering. But the problem I am experiencing also occurs when Zend_Translate is used. If I pass in a translation adapter to the form after calling Zend_Form#isValid(), everything gets translated except for the error messages. However, if I pass in the translation adapter *before* validating, everything works as expected. I've put together the following unit tests to confirm it: Unit tests: http://pastie.org/1241063 Result: http://pastie.org/1241069 It seems that the solution would be to update my form to apply the translation adapter in its init() method, but I've delegated that responsibility to the view script (similar to other view-related tasks in Matthew's blog). The main reason for that is due to our translations being stored in a CMS, which our model does not have access to (the model only contains business rules). Additionally, I'm not always rendering the form, so supplying a translation adapter when I only need to validate is a waste of resources. After some poking around through the source of Zend_Form_Element, there doesn't appear to be a way to directly modify the error messages. I ended up using ReflectionObject to manually modify Zend_Form_Element's protected $_messages array -- but this seems very hackish to me. Is there a better way? -- *Hector Virgen* Sr. Web Developer Walt Disney Parks and Resorts Online http://www.virgentech.com
