ZF-2876: Override locales with default

Description

Add a way to override auto locales with set ones. This feature would allow all classes which make use of I18N to have a fix locale set instead of using the detected one.

Comments

What's the problem with my patch, Thomas?

http://framework.zend.com/issues/secure/…

It takes only in account the Zend_Locale class itself. But this behaviour must also be integrated in all other locale aware classes at the same time.

And we will reuse the setDefault function instead of creating a new one.

In my opinion it should be marked as major and resolved ASAP. Now if you would like to override locale you have to pass your own locale to all of the constructors and static methods of Zend_Currency, Zend_Date, Zend_Measure etc.

I think the simplest way to resolve it is use of some static flag to disable all automatic detections of locale in favor of use default value.

That's exacly what my patch was doing.

Current setDefault() behaves as a fallback option / option of last resort. self::$_Default in 1.5.2 is never used to set the locale directly, it is only returned as last option in getDefault().

I was expecting it to set the locale to use when no other is specified in the constructor.

I've patched my Locale.php as follows to cover my needs:


Index: Locale.php
===================================================================
--- Locale.php  (revision 9641)
+++ Locale.php  (working copy)
@@ -116,6 +116,9 @@
      */
     public function __construct($locale = null)
     {
+        if (null === $locale and !empty(self::$_Default)) {
+            $locale = self::$_Default;
+        }
         if (empty(self::$_auto)) {
             self::$_auto        = $this->getDefault(null, false);
             self::$_browser     = $this->getDefault(self::BROWSER, false);

That patch is not really good Vincent, as it breaks B/C

I know, this is just a temp fix for my situation. I hate making big patches to ZF in anticipation of coming fixes. Although this brakes functional B/C, my code won't break (give errors) after a framework update. If Zend_Date and co wheren't calling Zend_Locale directly, I would have subclassed it.

Anyway a warning for others: DON'T USE THE ABOVE PATCH, unless you know exactly what is does and what it breaks!

I've send a mail to fw-i18n@lists to discuss this and some other items.

As you may have mentioned I added this new feature as request and I am also aware of the problems.

And as BC breaks are not allowed and I had not the time to do some deeper research on this feature I have not implemented it for now.

Please be patient.

I am very restrictive to patches as the I18N core has constraints to almost half of the Zend Framework and not only to the locale class itself as I have to compare the change to all components and their usage. This is not a simple task.

It will be implemented, but not in the next few days. It will be integrated in the next release after 1.6.

A default locale has been added within trunk. Use setDefault() / getDefault() and 'default' as autosetting.

Beware: As mentioned this is a BC break. Be aware of possible merging problems when using the old auto behaviour.

Updating for the 1.6.0 release.