Issues

ZF-2847: Multi Element With Arrays Calling isTranslated Produces Warning

Description

When using translation and a multi element with arrays as the options (optgroup), warnings are raised. Can be fixed by checking parameters prior to calling Translate::isTranslated and/or Translate::isTranslated should have some sanity checks on the parameters.

Controller:


$translate = new Zend_Translate('array', array('Select Test'=>'Select Test Translated'), 'en');
Zend_Registry::set('Zend_Translate', $translate);
$form = new Zend_Form(array(
    'elements' =array(
        'test' =array('Select', array(
            'label' ='Select Test',
            'MultiOptions' =array(
                'Group 1' =array(
                    '1-1' ='Hi 1-1',
                    '1-2' ='Hi 1-2'
                ),
                'Group 2' =array(
                    '2-1' ='Hi 2-1',
                    '2-2' ='Hi 2-2'
                ),
            )
        ))
    )
));
$this->view->form = $form;

With...

View: ```

Produces...

Warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer in /directory/library/Zend/Translate/Adapter.php on line 452

Comments

Please categorize/fix as needed.

Arthur: Please re-test this with the release. I have in mind that such an error was already reported and fixed before the release. Eighter with 1.5 or 1.5.1.

The problem still exists with ZF version 1.5.1.

This may not necessarily be a Translate problem, but I categorized it under Form and Translate as that is where the problem occurs. Form multi elements are passing ARRAYS to the Translate Adapter. This can be easily duplicated by using the test code I posted.

Should check the value in the multielement and make sure it is not an array before calling, or in the translate adapter, should make sure the passed in parameter is acceptable, or both.

2 things to mention:

First: It seems that 1.5.1 does not include the latest version of Zend_Translate. It has changed on 15.3, the release was done on 24.3 but does not include the change from 10 days ago... don't ask me why.

Second: Even if you use the actual trunk version where this has changed, you will not have the nested array from your optgroup translated because nested arrays can not be supported at translation. So you would have no error but also your optgroup not translated.

I will check out the latest trunk and try and test.

Like I said, I didn't necessarily think this was a Zend_Translate, problem. If the errors are gone, that's good.

The optgroup will have to be iterated over and translated, which is Zend_Form.

Hah... I already know the problem...

API Doc for isTranslated() and translate() states that $messageId can only be string. Zend_Form gives an array instead an string.

So in my opinion raising the error is ok because API doc states so. What if anyone gives an object as $messageId... this would also throw errors.

I detach Zend_Translate from this issue, as it's behaving correct related to it's allowed input.

This is a (failing) test for this issue.

I attached a patch that should fix this issue. Have a look at it. I'll be glad if it makes it into the framework.

Scheduling for next mini release.

Is it possible to include the fix in the current trunk, so we don't have to wait until 1.5.2 is released?

Emil: patience, please. I've scheduled it for the next mini release, but the fix will be in trunk first. I have a backlog of some 30 issues I need to hit before 1.5.2, and this is just one.

Fix committed to trunk and 1.5 release branch as of r9411

The optgroup label does not get translated.