views:

24

answers:

1

This is my code

$locale = new Zend_Locale('en_US');
Zend_Registry::set('Zend_Locale', $locale);

$GLOBALS['translate'] = new Zend_Translate(
    array(
        'adapter' => 'array',
        'content' => array('Hello' => 'Hi'),
        'locale'  => 'en_US'
    )
);

gb('translate')->addTranslation(
    array(
        'content' => array('Hello' => 'Xin chào'),
        'locale' => 'vi'
    )
);

gb('translate')->_('Hello'); //always print Xin chào

It's always print 'Xin chào' even I use web proxy (from US) to request page.

+1  A: 

Zend_Translate is locale aware, which means it will use the Zend_Locale instance stored in the Zend_Registry:

$locale = new Zend_Locale('en_US');
Zend_Registry::set('Zend_Locale', $locale);

If you are not using the Zend_Registry, it will try to get the locale from the user's web browser (if available), information from the environment of the host server, and Zend Framework settings. To prevent this, you have to set the locale explicitly:

$translator->setLocale($locale);

See the chapter Automatic Handling of Languages in the reference guide for Zend_Translate

Gordon