Zend Translate doesn't find language

dextervip picture dextervip · Dec 12, 2011 · Viewed 11.4k times · Source

I've got a Zend Translate Issue. I have configure the zend translate in the bootstrap like below

public function _initTranslate() {
    $locale = new Zend_Locale();
    Zend_Registry::set('Zend_Locale', $locale);

    $translate = new Zend_Translate(array(
                'adapter' => 'ini'
                    )
    );

    $translate->addTranslation(
            array(
                'content' => APPLICATION_PATH . '/configs/languages/pt.ini',
                'locale' => 'pt'
            )
    );
    $translate->addTranslation(
            array(
                'content' => APPLICATION_PATH . '/configs/languages/en.ini',
                'locale' => 'en'
            )
    );

    $translate->setLocale($locale);
    Zend_Registry::set('Zend_Translate', $translate);
}

I've added the languages and in my views I used translate helper but it shows me the following erros

Notice: The language 'en' has to be added before it can be used. 
in C:\xampp\ZendFramework-1.11.10\library\Zend\Translate\Adapter.php 
on line 443
Notice: No translation for the language 'en' available. 
in C:\xampp\ZendFramework-1.11.10\library\Zend\Translate\Adapter.php 
on line 456

I've followed zendframework reference guide. What I am doing wrong?

Answer

Yes Barry picture Yes Barry · Dec 12, 2011

Did you try passing a language to Zend_Locale?

$locale = new Zend_Locale('en_US');

Additionally, I found a work around:

$locale = new Zend_Locale(Zend_Locale::BROWSER);

$translate = new Zend_Translate(
    'ini',
    $yourPath,
    null,
    array('scan' => Zend_Translate::LOCALE_DIRECTORY));

// setting the right locale
if ($translate->isAvailable($locale->getLanguage())) {
    $translate->setLocale($locale);
} else {
    $translate->setLocale('en_US');
}

See http://framework.zend.com/issues/browse/ZF-6612 for more details. Note: this is a bug for 1.8, I see you're using 1.10 but the work-around might still work.

This is also a good thread: http://zend-framework-community.634137.n4.nabble.com/how-handle-Locale-td659923.html

Also, Zend_Translate offers an option to disable notices specifically for that class. If the content is being translated, then this (according to Zend) is not an "error" and notices should be disabled.

// as a fourth parameter to Zend_Translate pass it:
array('disableNotices' => true);