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.

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

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.