Issues

ZF-2861: Zend_Form validators messages are not translated

Issue Type: Bug Created: 2008-03-11T11:04:21.000+0000 Last Updated: 2008-03-21T17:34:13.000+0000 Status: Resolved Fix version(s): - 1.5.1 (25/Mar/08)

Reporter: Hristo Angelov (hedonism) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: Attachments:

Description

When is set translator to the form not all of the messages passed by validators can be translated. For example automatically added NotEmpty validator and when validating email address the automatically added Hostname validator.

Previously in my code i have this

<pre class="highlight">
$translator = new Zend_Translate('csv', $translation_file, 'bg');
Zend_Registry::set('translator', $translator);

Then in UsersController registerAction i have this code

<pre class="highlight">
        $form = new Zend_Form();
        
        $translator = Zend_Registry::get('translator');
        $form->setTranslator($translator);
        
        $form->setAttrib('id', 'users_registration_form');
        
        $form->addElement('text', 'username', array('label' => 'username'));
        $form->addElement('password', 'password', array('label' => 'password'));
        $form->addElement('text', 'first_name', array('label' => 'firstName'));
        $form->addElement('text', 'last_name', array('label' => 'lastName'));
        $form->addElement('text', 'email', array('label' => 'email'));
        $form->addElement(
            'submit',
            'do_register',
            array('label' => 'register')
        );
        
        $form->username->addValidator('Alnum');
        $form->username->setRequired(true);
        $form->username->setAttrib('onBlur', 'checkUsername();');
        
        $form->password->addValidator('Between', false, array(6, 12));
        $form->password->setRequired(true);
        
        $form->email->addValidator('EmailAddress');
        $form->email->setRequired(true);
        
        $form->email->setTranslator($translator);
        
        $form->first_name->addValidator('Alpha');
        $form->first_name->setRequired(true);
        
        $form->last_name->addValidator('Alpha');
        $form->last_name->setRequired(true);

In translation csv file i have this rows

<pre class="highlight">
notAlnum;'%value%' не съдържа само цифри и букви.
notAlpha;'%value%' не съдържа само букви.
stringEmpty;'%value%' не трябва да е празен стринг.
notBetween;'%value%' не е между '%min%' и '%max%' символа.
notBetweenStrict;'%value%' не е между '%min%' и '%max%' символа.

emailAddressInvalid;'%value%' не е валиден e-mail адрес във формата потребител@хост
emailAddressInvalidHostname;'%hostname%' не е валиден хост за e-mail '%value%'
emailAddressInvalidMxRecord;'%hostname%' не е валидем MX запис за e-mail '%value%'
emailAddressDotAtom;'%localPart%' не съвпада с dot-atom формата
emailAddressQuotedString;%localPart%' не съвяада със quoted-string формата
emailAddressInvalidLocalPart;'%localPart%' не е валиден потевител за e-mail '%value%'

hostnameIpAddressNotAllowed;'%value%' изгежда е IP адрес но IP адресите не са позволени
hostnameUnknownTld;'%value%' изглежда е DNS хост но неможе да съвпадне с TLD листата
hostnameDashCharacter;'%value%' изглежда е DNS хост но съдържа тире (-) на неправилна позиция
hostnameInvalidHostnameSchema;'%value%' изглежда е DNS хост но неможе да съвпадне със хост схемата за TLD '%tld%'
hostnameUndecipherableTld;'%value%' изглежда е DNS хост но cannot extract TLD част
hostnameInvalidHostname;'%value%' не съвпада със очакваната структура за DNS хост
hostnameInvalidLocalName;'%value%' изглежда не е валидна локална мрежа
hostnameLocalNameNotAllowed;'%value%' излгевда е локална мрежа но локалните мрежи не са позволени

notIpAddress;'%value%' не изглежда да е IP адрес

username;Потребител
password;Парола
email;E-Mail
firstName;Име
lastName;Фамилия
register;Регистрация

invalidFormData;Неправилно попълнена форма
usernameAlreadyExists;Потербителското име е заето
registrationSuccessfull;Успешна регистрация

So i also add dump in translate method of Zend_Translate_Adapter class to see witch messages ids are passed there. It seems that automatically added validators are never passed to translator such as NotEmpty, Ip and Hostname validators.

Expected result is to be all messages translated instead of only manually added validators messages.

Comments

Posted by Matthew Weier O'Phinney (matthew) on 2008-03-11T11:18:08.000+0000

I cannot reproduce the isssue. Please provide:

  • Code required to reproduce, including any translations
  • Expected result
  • Actual result

Until I have that information, I cannot evaluate.

Posted by Matthew Weier O'Phinney (matthew) on 2008-03-11T11:18:40.000+0000

Downgrading priority until I get reproduce code from reporter.

Posted by Hristo Angelov (hedonism) on 2008-03-12T03:19:44.000+0000

Hi there. I edit the issue and add code examples. Thank you.

Posted by Matthew Weier O'Phinney (matthew) on 2008-03-12T07:49:39.000+0000

Scheduling for 1.5.0 final release.

First off, for required elements, if a NotEmpty validator is not present, we automatically add one to the top of the validator stack for that element. You need to have an 'isEmpty' key in your translation file to ensure its message gets translated -- which you don't. Add that in, and that issue will go away.

I think I know what's going on with the email validator, and will attempt to provide a fix before the final 1.5.0 release.

Posted by Hristo Angelov (hedonism) on 2008-03-12T10:09:57.000+0000

Thank you.

Posted by Matthew Weier O'Phinney (matthew) on 2008-03-14T07:39:31.000+0000

Rescheduling for 1.5.1. This issue will affect only a small number of users, and is not deemed critical for addressing in the 1.5.0 release.

Posted by Matthew Weier O'Phinney (matthew) on 2008-03-21T16:38:59.000+0000

Fixed in trunk and 1.5 release branch

Posted by Wil Sinclair (wil) on 2008-03-21T17:34:13.000+0000

I'm assuming this fix is merged to the 1.5 release branch for release with 1.5.1. Please update JIRA if this is not the case.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts