ZF-7214: addTranslation 'clear' option is sticky!
Description
When using the Zend_Translate_Adapter->addTranslation() with the 'clear' option. The clear option sticks and data never gets set.
here is my work around: {quote} $adapter->addTranslation($data,$locale,array('clear'=>true)); //due to a bug in zend , 'clear' is sticky, so we need to unset it ! $adapter->addTranslation($data,$locale,array('clear'=>false)); //now you can add more data {quote}
This might be only in the gettext adapter
Comments
Posted by Thomas Weidner (thomas) on 2009-07-07T05:13:45.000+0000
What do you mean with "sticky" ?
The clear options erases previous set data so only the newly given data is available. It works only for the given locale.
Additionally all set options are internally stored so they don't have to be given again as this would not work when searching through directory structures.
Posted by Thomas Weidner (thomas) on 2009-07-07T05:14:57.000+0000
Changing priority as it does not block behaviour.
Posted by Yisrael Dov (yisraeldov) on 2009-07-07T05:20:56.000+0000
actually it does block behavior.
if you call:
$adapter->addTranslation($data,$locale,array('clear'=>true));
and then call
$adapter->addTranslation($data2,$locale);
the second call will also have option['clear'] set to true. That means that $data2 will overwrite $data.
even worse than this $data and $data2 will be cleared immediately and the translation adapter will have no data!
Posted by Thomas Weidner (thomas) on 2009-07-07T05:39:41.000+0000
Again: This is expected behaviour.
Options are set and stored so they don't have to be given again as described before. A simple call of setOptions() does also set options but will not add data.
And the translation adapter does not have no data... the data which are read with the call of addTranslation are always available even if you give the 'clear' option.
Posted by Thomas Weidner (thomas) on 2009-07-07T08:04:27.000+0000
Also to mention as I just saw it:
The input $data and $data2 is not touched by Zend_Translate. It does not delete given data, it could just access it's own data.
What you described is not possible by Zend_Translate. I expect that you access and delete your input data in another way.
Posted by Yisrael Dov (yisraeldov) on 2009-07-08T03:29:54.000+0000
Here I will show an example that might make it more clear :
In the above example my fix was commented out.
The expected behaviour when using clear, is that the old data will be replaced but the new data. Not that it will remain with no data at all!
Additionally I would expect that the clear would only happen once, not every time I call addTranslation.
But if I use my fix it works like expected.
Let me know if this is still not clear.
(Additionally if the intended behaviour of the 'clear' option was to leave the adapter without any data, then the data paramater should not be required!)
Posted by Yisrael Dov (yisraeldov) on 2009-07-08T03:56:11.000+0000
I've noticed this problem also in 1.8.1 and 1.8.4
Posted by Thomas Weidner (thomas) on 2009-08-25T13:01:24.000+0000
Fixed with r17813