Issues

ZF-3980: Zend_Locale unable to use user's browser locale settings

Description

In the constructor of Zend_Locale, each protected autodetected locale is populated calling getDefault(mode, false). Using false as the second argument pushes the environment autodetected locale over the browser's one. So if I set Romanian in the browser, an English locale comes down from the environment setting and becomes the first choice.

If I'm missing something, my bad. But at this point I can't seem to be able to use the user's browser locale. In my opinion, in Zend_Locale's constructor (and I think in another place in that file), the getDefault method should be called with true as the second argument.

Suggested fix following; the _auto member would be ok to be built after the original behavior, merging browser and environment. But _browser and _environment should only contain those locales.

Index: library/Zend/Locale.php

--- library/Zend/Locale.php (revision 27) +++ library/Zend/Locale.php (working copy) @@ -173,8 +173,8 @@ { if (empty(self::$_auto) === true) { self::$_auto = $this->getDefault(null, false); - self::$_browser = $this->getDefault(self::BROWSER, false); - self::$_environment = $this->getDefault(self::ENVIRONMENT, false); + self::$_browser = $this->getDefault(self::BROWSER, true); + self::$_environment = $this->getDefault(self::ENVIRONMENT, true); if ((empty($locale) === true) and (empty(self::$_auto) === true) and (empty(self::$_default) === true)) { require_once 'Zend/Locale/Exception.php'; @@ -830,8 +830,8 @@ if (empty(self::$_auto) === true) { $temp = new self($locale); self::$_auto = $temp->getDefault(null, false); - self::$_browser = $temp->getDefault(self::BROWSER, false); - self::$_environment = $temp->getDefault(self::ENVIRONMENT, false); + self::$_browser = $temp->getDefault(self::BROWSER, true); + self::$_environment = $temp->getDefault(self::ENVIRONMENT, true); }

     if ($locale === 'auto') {

Taken a look at the trunk version - seems much closer to what I imagined ;) Haven't tested it yet but you may close this issue - seems pretty much solved. Thanks!

By the way, why can't I post comments?

Comments

The I18N core can changed 4 weeks ago but is not allowed to be integrated until 1.7. Can you please try if you have problems with actual trunk and give us feedback ?

Fixed in trunk with new implementation

Updating for the 1.6.0 release.