+ Reply to Thread
Results 1 to 8 of 8

Thread: Default Locale isn't used

  1. #1
    Louis is offline Junior Member
    Join Date
    Feb 2010
    Posts
    4

    Question Default Locale isn't used

    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:

    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
    Also I have translations set up for English and Dutch, which work.

    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:

    Code:
    tree_key;Tree
    flower_key;Flower
    So what I get is that 'tree_key' and 'flower_key' are shown instead of the expected 'Tree' and '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

  2. #2
    Louis is offline Junior Member
    Join Date
    Feb 2010
    Posts
    4

    Default

    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..

  3. #3
    thomas is offline Senior Member
    Join Date
    Aug 2008
    Posts
    173

    Default

    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.
    Greetings
    Thomas Weidner
    I18N Team Leader, Zend Framework
    http://www.thomasweidner.com

  4. #4
    Louis is offline Junior Member
    Join Date
    Feb 2010
    Posts
    4

    Default

    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.

  5. #5
    alokin is offline Senior Member
    Join Date
    Apr 2009
    Posts
    192

    Default

    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.

  6. #6
    Louis is offline Junior Member
    Join Date
    Feb 2010
    Posts
    4

    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:
    When the systems locale could not be detected Zend_Locale will use it's default locale, which is set to en per default.
    So why doesn't this happen? It's exactly what I want.

  7. #7
    aschk is offline Junior Member
    Join Date
    Jul 2008
    Posts
    6

    Default

    Surely you've partly answered your question:

    When the systems locale could not be detected Zend_Locale will use it's default locale, which is set to en per default.
    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".

    What you require is some logic to resolve your problem:

    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());
    }
    You can stick this in your bootstrap.
    Last edited by aschk; 03-30-2010 at 09:35 AM.

  8. #8
    FWmaster is offline Junior Member
    Join Date
    Jul 2010
    Posts
    1

    Lightbulb

    Quote Originally Posted by aschk View Post

    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());
    }
    You can stick this in your bootstrap.
    This can't work :

    Code:
    $this->bootstrap('translate');
    initialization of the resource checks if detected language file exists and returns the notice before you check availability.

    You must force translate default locale in application.ini :

    Code:
    resources.translate.locale = "en"
    then check locale language in bootstrap and change translate locale if available

    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);

+ Reply to Thread

Similar Threads

  1. Zend_Date, set day to Monday this week according to locale
    By Holmen in forum Internationalization (i18n) & Localization (l10n)
    Replies: 0
    Last Post: 06-20-2010, 01:18 PM
  2. Message: The locale 'HH' is no known locale
    By phpveteran in forum General Q&A on Zend Framework
    Replies: 2
    Last Post: 02-24-2010, 07:16 PM
  3. Zend Navigation and Locale
    By bo bo in forum Model-View-Controller (MVC)
    Replies: 1
    Last Post: 08-31-2009, 10:02 PM
  4. Zend Route Hostname + locale
    By gentlemich in forum Model-View-Controller (MVC)
    Replies: 1
    Last Post: 06-30-2009, 12:16 AM
  5. setDefault Locale for Zend_Locale
    By friedhelm in forum Internationalization (i18n) & Localization (l10n)
    Replies: 0
    Last Post: 04-18-2008, 11:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts