ZF-2861: Zend_Form validators messages are not translated


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

$translator = new Zend_Translate('csv', $translation_file, 'bg');
Zend_Registry::set('translator', $translator);

Then in UsersController registerAction i have this code

        $form = new Zend_Form();
        $translator = Zend_Registry::get('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'));
            array('label' => 'register')
        $form->username->setAttrib('onBlur', 'checkUsername();');
        $form->password->addValidator('Between', false, array(6, 12));

In translation csv file i have this rows

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 адрес


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.


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.

Downgrading priority until I get reproduce code from reporter.

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

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.

Thank you.

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.

Fixed in trunk and 1.5 release branch

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.