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

Issue Type: Bug Created: 2008-03-10T15:05:45.000+0000 Last Updated: 2008-05-14T23:52:01.000+0000 Status: Resolved Fix version(s): - 1.5.2 (15/May/08)

Reporter: Arthur Kang (arthurkang) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: Attachments: - MultiselectTest.php.patch


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.


<pre class="highlight">
$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;


View: ```


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


Posted by Wil Sinclair (wil) on 2008-03-25T20:29:10.000+0000

Please categorize/fix as needed.

Posted by Thomas Weidner (thomas) on 2008-04-05T07:32:24.000+0000

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.

Posted by Arthur Kang (arthurkang) on 2008-04-07T04:53:09.000+0000

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.

Posted by Thomas Weidner (thomas) on 2008-04-09T15:49:21.000+0000

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.

Posted by Arthur Kang (arthurkang) on 2008-04-09T16:16:19.000+0000

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.

Posted by Thomas Weidner (thomas) on 2008-04-09T16:38:12.000+0000

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.

Posted by Emil Ivanov (vladev) on 2008-04-14T03:36:12.000+0000

This is a (failing) test for this issue.

Posted by Emil Ivanov (vladev) on 2008-04-18T03:00:36.000+0000

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.

Posted by Matthew Weier O'Phinney (matthew) on 2008-04-22T13:32:23.000+0000

Scheduling for next mini release.

Posted by Emil Ivanov (vladev) on 2008-04-25T03:19:21.000+0000

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

Posted by Matthew Weier O'Phinney (matthew) on 2008-04-25T06:55:58.000+0000

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.

Posted by Matthew Weier O'Phinney (matthew) on 2008-05-08T07:30:41.000+0000

Fix committed to trunk and 1.5 release branch as of r9411

Posted by Emil Ivanov (vladev) on 2008-05-14T23:51:59.000+0000

The optgroup label does not get translated.

Have you found an issue?

See the Overview section for more details.


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

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