Is Zend Translate an automatic language detection?

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 always prints "Xin chào", even I use a web proxy (from the USA) to request a page.

+3
source share
1 answer

Zend_Translateis a locale icon, which means that it will use the instance Zend_Localestored in Zend_Registry:

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

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

$translator->setLocale($locale);

See the Automatic Language Processing chapter in the reference guide forZend_Translate

+4

Source: https://habr.com/ru/post/1767501/


All Articles