Would someone be so kind to let me know if I'm using this the correct way or not? I'm still struggling with this..
Hi all,
I've been trying to get translations going in my application. And it all works, except for one thing: the default translation if the user locale isn't available.
I've got my application.ini set up as folllows:
Also I have translations set up for English and Dutch, which work.Code:resources.locale.default = "en" resources.translate.data = APPLICATION_PATH "/../languages" resources.translate.adapter = "csv" resources.translate.options.scan = "directory" resources.translate.options.disableNotices = true
However, when I visit my site with the browser set to (for instance) Spanish, the application doesn't fall back to English as I would expect, but instead shows the translation keys. That is, my translation files look something like this:
So what I get is that 'tree_key' and 'flower_key' are shown instead of the expected 'Tree' and 'Flower'.Code:tree_key;Tree flower_key;Flower
Am I missing some fundamentals here?
Last edited by Louis; 02-09-2010 at 11:46 AM. Reason: Decided to elaborate on my translation files
Would someone be so kind to let me know if I'm using this the correct way or not? I'm still struggling with this..
Question in return:
You set a default locale for Zend_Locale...
And you set 2 translations for Zend_Translate...
How should Zend_Locale know which translation languages are available ?
I would expect that this is something which only Zend_Translate knows and not Zend_Locale.
Take a look at the application resources.
Thank you for your reply.
Are you suggesting that I should use a 'resources.translate.default' or 'resources.translate.locale' entry for the application.ini file? **
'cause that doesn't work.
With the first the translations fall back to the translation keys for unknown languages and with the latter the translations are set to that language exclusively, not taking into account the locale that is coming in through the browser...
** I can't seem to be able to find a good overview of which resources are allowed.
Zend Framework: Documentation: Available Resource Plugins - Zend Framework Manual doesn't seem to be exhausting all options.
Last edited by Louis; 03-20-2010 at 03:12 AM.
And which version of ZF you are using? Note that new option for Locale app resource was introduced in ZF v1.10, named "force", which enables you to pick whether locale supplied in "default" option param should be forced, or otherwise, resource will be initialized in a way that Zend_Locale will try to auto detect locale, which is done by default.
I'm using ZF 1.10. I tried using a resources.locale.force = false, but it doesn't change anything. With the force option set to true all locales see the default translation.
Basically I'm still stuck with the choice between either translation keys for unknown locales or using a single language. By the way, I'm still not sure about those keys in my previous post.
This can't be that hard, right? Isn't there a gazillion sites out there using translations based on the Zend Framework?
According to the documentation:
So why doesn't this happen? It's exactly what I want.When the systems locale could not be detected Zend_Locale will use it's default locale, which is set to en per default.
Surely you've partly answered your question:
The point is that Zend_Locale DID correctly determine your locale to be spanish "es" or "es_es" (etc), so it had no requirement to fallback to your default "en".When the systems locale could not be detected Zend_Locale will use it's default locale, which is set to en per default.
What you require is some logic to resolve your problem:
You can stick this in your bootstrap.Code:// Bootstrap application wide locale 1st. $this->bootstrap('locale'); // Bootstrap translation. $this->bootstrap('translate'); // Grab the resources. $locale = $this->getResource('locale'); $translate = $this->getResource('translate'); // See is our language option is available. if(!$translate->isAvailable($locale->getLanguage())){ // Our language option isn't available // so set the locale in translate, to the default locale. $translate->setLocale($locale->getDefault()); }
Last edited by aschk; 03-30-2010 at 09:35 AM.
This can't work :
initialization of the resource checks if detected language file exists and returns the notice before you check availability.Code:$this->bootstrap('translate');
You must force translate default locale in application.ini :
then check locale language in bootstrap and change translate locale if availableCode:resources.translate.locale = "en"
Code:// detect locale language $this->bootstrap('locale'); $lang = $this->getResource('locale')->getLanguage(); // init translate with default locale (en) $this->bootstrap('translate'); $translate = $this->getResource('translate'); // change translate locale with detected language if available if ($translate->isAvailable($lang)) $translate->setLocale($lang);