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

Reply via email to