开发者

Does Zend Translate auto detect language?

开发者 https://www.devze.com 2023-01-18 14:03 出处:网络
This is my code $locale = new Zend_Locale(\'en_US\'); Zend_Regis开发者_如何学运维try::set(\'Zend_Locale\', $locale);

This is my code

$locale = new Zend_Locale('en_US');
Zend_Regis开发者_如何学运维try::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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号