Issues

ZF-9885: CLONE -logging not found translations does not work with Zend_Validate, Zend_Form_Element_Multi, Zend_Dojo_Form_Element_DijitMulti

Description

Not found translations are logged in the translators translate() Method if the translations does not exist.

Zend/Validate/Abstract.php, Zend/Form/Element/Multi.php and Zend/Dojo/Form/Element/DijitMulti.php first check if there is an existing translation with isTranslated() and only if theres a translation the translate() Method is called. If the translation does not exist, the translation won't be logged because of the missing call of translate()!

I've two ways to solve this problem:

  • change Zend_Validate_Abstract etc. to just call translate() instead of checking if there is an existing translation

or

  • enable logging of missing translations in method isTranslated() in Zend_Translate

Maybe there are more components affected by this issue.

Comments

This problem is still open in version 1.10.4.

Reproducing it is quite simple, just create a Zend_Form_Element_Select field with a translator enabled and no translation done and add a few values in it.

At line 311 in Zend_Form_Element_Multi, you'll see that this code is called :

 
if ($translator->isTranslated($value)) {
    return $translator->translate($value);
}

and Zend_Translate_Adapter->isTranslated() method doesn't log anything before returning false.

So all the values in that select field won't figure in the missing translations log.

Can you please clearify if it's now a failure or not a failure. Both states are not possible at the same time.

You should also note that logging of untranslated messages depend on the used settings for Zend_Translate. Per default log is NOT enabled because you must attach a log where Zend_Translate can write to.

Logging of untranslated messages is activated in my test case.

My opinion is that it's a failure because it works for every other Zend components, examples: input's labels, standard translation, etc... But not in a few cases listed above or in the cloned issue.

I am not talking about optimization or if we should use the isTranslated method. But only about the final result: no log entries for untranslated messages when there should be some.

As you said that it's working I will detach Zend_Translate from the components being buggy.

As you said there's a bug I am detaching the "fixed for version 1.8" tag

Agreed and fixed for Zend_Form_Element and Zend_Dojo_Form_Element with r22322.

Not agreed and no bug for Zend_Validate. Zend_Validate must provide the capability to translate the message constants as also the content.

Not agreed for Zend_Translate. IsTranslated must not throw a notice when checking if a message is translateable.

For me, Zend_Validate_Abstract is buggy as well simply because if the getMessages() method is used, like it's done in Zend_Form_Element (line 1368, v1.10), the _createMessage() method in Zend_Validate_Abstract is used to generate the error messages, and in that method, the problem is exactly the same than specified above.

See the code below of the _createMessage() method:

 
if (null !== ($translator = $this->getTranslator())) {
    if ($translator->isTranslated($message)) {
        $message = $translator->translate($message);
    } elseif ($translator->isTranslated($messageKey)) {
        $message = $translator->translate($messageKey);
    }
}

The message is not logged because isTranslated() is used.

To re-create the problem, create a Form with a Zend_Form_Element_Text element, setRequired(true) and add a NotEmpty validator. Submit the form with nothing in the field.

Be aware that, if the element already has error messages, then everything work fine because _getErrorMessages() of Zend_Form_Element is used and isTranslated() in not used in that one.