Zend Framework

Multi Element With Arrays Calling isTranslated Produces Warning

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Trivial Trivial
  • Resolution: Fixed
  • Affects Version/s: 1.5.0RC1
  • Fix Version/s: 1.5.2
  • Component/s: Zend_Form
  • Labels:
    None
  • Fix Version Priority:
    Must Have

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:

<?=$this->form?>

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

Activity

Hide
Wil Sinclair added a comment -

Please categorize/fix as needed.

Show
Wil Sinclair added a comment - Please categorize/fix as needed.
Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Arthur Kang added a comment -

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.

Show
Arthur Kang added a comment - 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.
Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Arthur Kang added a comment -

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.

Show
Arthur Kang added a comment - 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.
Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Emil Ivanov added a comment -

This is a (failing) test for this issue.

Show
Emil Ivanov added a comment - This is a (failing) test for this issue.
Hide
Emil Ivanov added a comment -

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.

Show
Emil Ivanov added a comment - 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.
Hide
Matthew Weier O'Phinney added a comment -

Scheduling for next mini release.

Show
Matthew Weier O'Phinney added a comment - Scheduling for next mini release.
Hide
Emil Ivanov added a comment -

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

Show
Emil Ivanov added a comment - Is it possible to include the fix in the current trunk, so we don't have to wait until 1.5.2 is released?
Hide
Matthew Weier O'Phinney added a comment -

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.

Show
Matthew Weier O'Phinney added a comment - 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.
Hide
Matthew Weier O'Phinney added a comment -

Fix committed to trunk and 1.5 release branch as of r9411

Show
Matthew Weier O'Phinney added a comment - Fix committed to trunk and 1.5 release branch as of r9411
Hide
Emil Ivanov added a comment -

The optgroup label does not get translated.

Show
Emil Ivanov added a comment - The optgroup label does not get translated.

People

Vote (2)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: