-- Dividy <[EMAIL PROTECTED]> wrote
(on Monday, 04 February 2008, 09:42 AM -0800):
> Thanks for all your good advices. I tried everything you proposed some days
> ago and it didn't give any good results. That's why i have come with this
> solution.
>
> But please, if you could give me an example of line you'd put in a csv file,
> that would be great :)
>
> e.g. I tried using "isEmpty;The string is empty" in my en.csv file and then
> put the translation in my fr.csv file, but it didn't work :)
You had it right... but there was a problem in trunk... while validation
in the *elements* was getting properly translated, the form object was
not injecting the translator into the elements... oops!
Corrected now in svn trunk.
> Thanks in advance for your precious time.
And thank you for the issue reporting!
> Matthew Weier O'Phinney-3 wrote:
> >
> > -- Dividy <[EMAIL PROTECTED]> wrote
> > (on Monday, 04 February 2008, 06:22 AM -0800):
> >> Dividy wrote:
> >> > For my first post on this nice forum, could someone explain me in
> >> details
> >> > how to translate the error messages of a zend_form validation ?
> >> >
> >> > I tried much thing but none work.
> >> >
> >> > Thanks.
> >>
> >> First, thanks for answering so fast because using Zend every day, is just
> >> a
> >> pure pleasure.
> >>
> >> Here's what i had came to while waiting for your answer :
> >
> > Please note my previous response -- this is no longer necessary using
> > the current svn trunk, as getMessages() now translates error messages by
> > default if a translate adapter is present and the error code is present
> > in the translations.
> >
> >> <?php
> >>
> >> $t=$form->getElements();
> >> foreach ($t as $element) {
> >> $validateurs=$element->getValidators();
> >> $validateurs_noms=array_keys($validateurs);
> >> for ($k=0;$k<count($validateurs_noms);$k++){
> >>
> >> if
> >> ($validateurs_noms[$k]=='Zend_Validate_StringLength'){
> >>
> >> $valobj=$element->getValidator($validateurs_noms[$k]);
> >> $valobj->setMessages( array(
> >>
> >> Zend_Validate_StringLength::TOO_SHORT => 'Les données saisies sont trop
> >> courtes',
> >>
> >> Zend_Validate_StringLength::TOO_LONG => 'Les données saisies sont trop
> >> trop
> >> longues'
> >> ));
> >> }
> >>
> >> if
> >> ($validateurs_noms[$k]=='Zend_Validate_Alnum'){
> >>
> >> $valobj=$element->getValidator($validateurs_noms[$k]);
> >> $valobj->setMessages( array(
> >>
> >> Zend_Validate_Alnum::STRING_EMPTY => 'Ce champ est requis',
> >>
> >> Zend_Validate_Alnum::NOT_ALNUM => 'Uniquement des chiffres et des
> >> lettres'
> >> ));
> >> }
> >>
> >> if
> >> ($validateurs_noms[$k]=='Zend_Validate_Regex'){
> >>
> >> $valobj=$element->getValidator($validateurs_noms[$k]);
> >> $valobj->setMessages( array(
> >>
> >> Zend_Validate_Regex::NOT_MATCH => 'Les données ne correspondent pas au
> >> format demandé'
> >> ));
> >> }
> >>
> >> if
> >> ($validateurs_noms[$k]=='Zend_Validate_InArray'){
> >>
> >> $valobj=$element->getValidator($validateurs_noms[$k]);
> >> $valobj->setMessages( array(
> >>
> >> Zend_Validate_InArray::NOT_IN_ARRAY => 'Mauvais choix, veuillez
> >> recommencer'
> >> ));
> >> }
> >>
> >> if
> >> ($validateurs_noms[$k]=='Zend_Validate_NotEmpty'){
> >>
> >> $valobj=$element->getValidator($validateurs_noms[$k]);
> >> $valobj->setMessages( array(
> >>
> >> Zend_Validate_NotEmpty::IS_EMPTY => 'Le champ est vide, veuillez le
> >> remplir'
> >> ));
> >> }
> >>
> >> if
> >> ($validateurs_noms[$k]=='Zend_Validate_EmailAddress'){
> >>
> >> $valobj=$element->getValidator($validateurs_noms[$k]);
> >> $valobj->setMessages( array(
> >>
> >> Zend_Validate_EmailAddress::INVALID => 'Adresse e-mail invalide,
> >> veuillez
> >> la vérifier',
> >>
> >> Zend_Validate_EmailAddress::INVALID_HOSTNAME => 'Adresse e-mail
> >> invalide,
> >> veuillez la vérifier',
> >>
> >> Zend_Validate_EmailAddress::INVALID_LOCAL_PART => 'Adresse e-mail
> >> invalide, veuillez la vérifier',
> >>
> >> Zend_Validate_EmailAddress::INVALID_MX_RECORD => 'Adresse e-mail
> >> invalide, veuillez la vérifier'
> >> ));
> >> }
> >>
> >>
> >> }
> >> }
> >> ?>
> >
> > --
> > Matthew Weier O'Phinney
> > PHP Developer | [EMAIL PROTECTED]
> > Zend - The PHP Company | http://www.zend.com/
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Zend_Form-and-validation-language-tp15248574s16154p15270531.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
--
Matthew Weier O'Phinney
PHP Developer | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/