ZF-2904: Zend_Translate_Adapter ignores parameters when cache is used


German text 1English text 1


As stated in the manual you MUST set the cache BEFORE creating the object. See…

Using the same cache for different objects like in your case makes of course problems not only in this component... it leads to unexpectable behaviour as you do not know what's written and what's left from the first object.

But that is what my example code does: It creates and sets the cache, and then (by calling testTranslate()) twice creates a translate object and uses it. If you want, you can rewrite it to

$translationCache = Zend_Cache::factory('Page', 'File');

$translate1 = new Zend_Translate('tmx', 'texts.tmx', 'de');

Zend_Debug::dump($translate1->getLocale(), 'Locale');
Zend_Debug::dump($translate1->getMessages(), 'Messages');

$translate2 = new Zend_Translate('tmx', 'texts.tmx', 'de');

Zend_Debug::dump($translate2->getLocale(), 'Locale');
Zend_Debug::dump($translate2->getMessages(), 'Messages');

which clearly is what the documentation says and does not work either. The point is not that the example creates two instances at the same time, the point is that writing and restoring from and to the cache will lead to parameters being ignored. Please have a look at Zend_Translate_Adapter's constructor, it is obviously not correct.

2 things to mention:

*) You must not use the incubator in such situations *) You can try r9038 or higher where the options have been added to cache

But it has to be mentioned that using caches in the way you show it, is problematic. It is not allowed to have 2 identical adapters with different options. This is against generic rules and leads to the problem that the user has to be aware of which class holds which translation. This is not allowed and also not supported.

With the actual revision there is no problem within your testcode.

Updating for the 1.6.0 release.