Sephen
Sephen

Reputation: 1111

Zend translate translates to english while locale is set to dutch

My Zend_translate is working but for some reason it only translates to english. Even when my locale is set to Dutch manually it shows the english translations. When I delete the english mo/po files it will use the dutch translations.

This is set in the bootstrap:

    $translate = new Zend_Translate('gettext',
                    APPLICATION_PATH . "/languages/",
                    null,
                    array('scan' => Zend_Translate::LOCALE_DIRECTORY));

    $registry = Zend_Registry::getInstance();
    $registry->set('Zend_Translate', $translate);
    //$translate->setLocale('nl_NL');

In the languages directory there are:en_US.mo, en_US.po, nl_NL.mo, nl_NL.po.

What am i doing wrong?

Upvotes: 0

Views: 685

Answers (2)

Michelangelo
Michelangelo

Reputation: 1397

Here my solution: Add this method in your bootstrap.php file.

protected function _initTranslate()
{
    $locale = new Zend_Locale(Zend_Locale::BROWSER);
    $langcode = $locale->getLanguage();

    $translate = new Zend_Translate(
                                    array(
                                        'adapter' => 'gettext',
                                        'content' => APPLICATION_PATH . "/langs/$langcode/$langcode.mo",
                                        'locale'  => $langcode,
                                    ));

    $registry = Zend_Registry::getInstance();
    $registry->set('Zend_Translate', $translate);
    $translate->setLocale('en');
}

Keep me updated about the problem!

bye

Upvotes: 1

siludnig
siludnig

Reputation: 35

You need to use Zend_Translate::LOCALE_FILENAME instead of Zend_Translate::LOCALE_DIRECTORY as you can see here: http://framework.zend.com/manual/1.12/en/zend.translate.additional.html#zend.translate.additional.options

The correct code would be:

$translate = new Zend_Translate('gettext',
                APPLICATION_PATH . "/languages/",
                null,
                array('scan' => Zend_Translate::LOCALE_FILENAME));

$registry = Zend_Registry::getInstance();
$registry->set('Zend_Translate', $translate);

Upvotes: 0

Related Questions