Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Not an Issue
-
Affects Version/s: 1.5.0
-
Fix Version/s: 1.5.1
-
Component/s: Zend_Translate
-
Labels:None
Description
In ZF 1.0.4 I have the following code, it successfully detects browser language setting and applies the translation and will downgrade through the list of languages the browser sends. Since upgrading to ZF 1.5 this no longer works and always returns the last language loaded (in my case Spanish!) even though the browser is set to en.
public function preDispatch(Zend_Controller_Request_Abstract $request) { $browserLocale = new Zend_Locale(Zend_Locale::BROWSER); Zend_Registry::set('browserLocale', $browserLocale->__toString()); setcookie('lang', $browserLocale->__toString(), null, '/'); $config = Zend_Registry::get('config'); $translate = new Zend_Translate("csv", "languages" . DS . "en" . DS . "lang.en", "en"); if (!empty($config->languages->lang)) { foreach ($config->languages->lang as $lang) { $translate->addTranslation("languages" . DS . $lang . DS . "lang." . $lang, $lang); } } if ($translate->isAvailable($browserLocale->__toString())) { //Zend_Registry::get('logger')->info("Setting language to " . $browserLocale); $locale = substr($browserLocale->__toString(), 0, 2); } else { //Zend_Registry::get('logger')->info("Language " . $browserLocale . " not found downgrading to " . $translate->getLocale()); $locale = substr($translate->getLocale(), 0, 2); } Zend_Registry::set('translate', $translate); Zend_Registry::set('locale', $locale); }
With your code you set all languages manually. This is the reason why it does not work for you.
The settings of your browser are ignored.
You have eighter to use "browser" or "auto" as locale to use the browser settings.
Also instead of adding each languages manually it is better to have this done automatically.