ZF-3930: When using caching with zend_tanslate it appears that no translation at all is performed
Description
When using caching with zend_tanslate it appears that no translation at all is performed
function indexAction(){
require_once 'Zend/Locale.php';
require_once 'Zend/Translate.php';
$config = Zend_Registry::get('config');
$this->locale = new Zend_Locale($config->setup->defaultLocale);
Zend_Registry::set('locale', $this->locale);
Zend_Translate::setCache(Zend_Registry::get('cache'));
Zend_Registry::set('Zend_Translate', new Zend_Translate('gettext', './Application/Locale/pl/default.mo', 'pl'));
}
removing Zend_Translate::setCache(Zend_Registry::get('cache')); - makes app work fine
Comments
Posted by Marcin Lulek (ergo14) on 2008-08-12T08:35:35.000+0000
test case
Posted by Matthew Weier O'Phinney (matthew) on 2008-08-12T10:15:52.000+0000
I tried to work this into a more succinct use case:
However, this worked fine. It may be an issue with the gettext adapter specifically, and I'll try that next.
Posted by Thomas Weidner (thomas) on 2008-08-12T10:23:56.000+0000
The adapter classes themself have no access to the cache. They only read the data and connect them to the abstract class.
The behaviour of the cache is completly independent of the used adapter.
Posted by Matthew Weier O'Phinney (matthew) on 2008-08-12T10:24:57.000+0000
Okay, I tried the following now:
I now get the following exception:
I get this error with or without caching. At this point, I cannot reproduce unless we get a valid translation file to test against.
Posted by Marcin Lulek (ergo14) on 2008-08-12T10:31:46.000+0000
default pl po file
Posted by Thomas Weidner (thomas) on 2008-08-12T10:32:32.000+0000
Question:
Are you changing the locale when using the same cache ? Because actually caching is only done for the complete adapter...
When you set the cache and want to load another language afterwards it will not be recognised. Caching is only done for the complete adapter at initiation.
You should add all languages/files once.
There exists already an issue (ZF-3071) which will add this behaviour (caching on file-basis/adding translations afterwards to the cache). But it is not implemented for now.
The actual solution is to use a locale-based cache.
Posted by Marcin Lulek (ergo14) on 2008-08-12T10:34:45.000+0000
polish mo file
Posted by Thomas Weidner (thomas) on 2008-08-12T10:35:11.000+0000
A po file will not be recognised by Zend_Translate... you should add the related binary gettext file (*.mo)
Posted by Matthew Weier O'Phinney (matthew) on 2008-08-12T10:38:36.000+0000
I've run the reproduce case I posted in an earlier comment against the .mo file linked in the issue, and it works both with and without caching.
Posted by Thomas Weidner (thomas) on 2008-08-12T10:45:12.000+0000
Is the string you wanted to translate available in the mo file ? Try to use isTranslated() to verify.
Is the right data loaded ? Try to use getList() and getMessages() to verify.
Try the translation itself without application as showed by Matthew to verify if it works or not.
Posted by Marcin Lulek (ergo14) on 2008-08-12T10:48:54.000+0000
simplified test case
Posted by Thomas Weidner (thomas) on 2008-08-12T11:08:11.000+0000
Running your testcode I get returned:
Ustawienia główne
Which seems to me like all is translated as required.
Posted by Matthew Weier O'Phinney (matthew) on 2008-08-12T11:16:32.000+0000
As noted on IRC, I've tried the above simplified test case, varying the cache lifetime as well as looping and setting random wait durations before translating -- in each case, I get the translated strings. This is looking like a caching issue.
Posted by Marcin Lulek (ergo14) on 2008-08-12T13:02:37.000+0000
the fix for the issue
on translate/adapter.php line 98:
add:
if($locale){$this->setLocale($locale); }
fixes the issue for me.
Posted by Thomas Weidner (thomas) on 2008-08-18T08:09:40.000+0000
Fixed with r10915
Posted by Wil Sinclair (wil) on 2008-09-02T10:39:45.000+0000
Updating for the 1.6.0 release.