Results 1 to 3 of 3

Thread: $translate->isAvailable() always true?

  1. #1
    PoolSnoopy is offline Junior Member
    Join Date
    Mar 2008
    Posts
    2

    Lightbulb [SOLVED] $translate->isAvailable() always true?

    Dear fellows,

    I have difficulties using or understanding Zend_Translate. Imagine the following code:

    try {
    Zend_Registry::get('translation');
    } catch (Zend_Exception $e) {
    $translate = new Zend_Translate('csv', '../translation/english.csv', 'en');
    $translate->addTranslation('../translation/german.csv', 'de');
    $translate->addTranslation('../translation/english_US.csv', 'en_US');
    Zend_Registry::set('translation', $translate);
    }
    ....
    $translate = Zend_Registry::get('translation');

    then I would expect that $translate->isAvailable('xx') to be false. but it is true. so how can I check whether a translation for the desired language is here or not?

    any help highly appreciated
    Last edited by PoolSnoopy; 03-21-2008 at 02:34 PM. Reason: SOLVED

  2. #2
    PoolSnoopy is offline Junior Member
    Join Date
    Mar 2008
    Posts
    2

    Default

    I'm not sure what was wrong before, but now this code works perfectly for me:

    $locale = new Zend_Locale();
    $translate = new Zend_Translate('csv', '../translation/english.csv', 'en');
    $translate->addTranslation('../translation/german.csv', 'de');
    $translate->addTranslation('../translation/english_US.csv', 'en_US');
    if (! $translate->isAvailable($locale->getLanguage())) {
    $translate->setLocale('en');
    } else {
    $translate->setLocale('auto');
    }

    Zend_Translate is now picking the right languages according to browser preferences and sticking to 'en' if an unknown or untranslated language is requested.

  3. #3
    ZendLearner is offline Junior Member
    Join Date
    Mar 2009
    Posts
    26

    Default I think its due to the fact that you used setLocale

    Quote Originally Posted by PoolSnoopy View Post
    I'm not sure what was wrong before, but now this code works perfectly for me:

    $locale = new Zend_Locale();
    $translate = new Zend_Translate('csv', '../translation/english.csv', 'en');
    $translate->addTranslation('../translation/german.csv', 'de');
    $translate->addTranslation('../translation/english_US.csv', 'en_US');
    if (! $translate->isAvailable($locale->getLanguage())) {
    $translate->setLocale('en');
    } else {
    $translate->setLocale('auto');
    }

    Zend_Translate is now picking the right languages according to browser preferences and sticking to 'en' if an unknown or untranslated language is requested.

    Hi, I think you have to call setLocale() after you add multiple translation files using addTranslation() in order for isAvailable() to detect whether translation is available.

Similar Threads

  1. translate each expression according his html id
    By Yosef in forum General Q&A on Zend Framework
    Replies: 0
    Last Post: 07-08-2010, 12:37 PM
  2. Validating a Select Form Element with NotEmpty and required=true
    By dvmorris in forum Core Infrastructure
    Replies: 3
    Last Post: 02-02-2010, 07:42 PM
  3. Router Translate troubles with modules
    By whisher in forum Model-View-Controller (MVC)
    Replies: 2
    Last Post: 12-10-2009, 12:25 PM
  4. Zend_Form getValues(true) to suppress array notation
    By ZendLearner in forum Model-View-Controller (MVC)
    Replies: 1
    Last Post: 12-07-2009, 08:20 AM
  5. Validate Empty when other field is true
    By jlavere in forum Core Infrastructure
    Replies: 7
    Last Post: 10-18-2009, 07:57 PM

Posting Permissions

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