ZF-2876: Override locales with default

Issue Type: New Feature Created: 2008-03-13T13:37:34.000+0000 Last Updated: 2008-09-02T10:38:51.000+0000 Status: Resolved Fix version(s): - 1.6.0 (02/Sep/08)

Reporter: Thomas Weidner (thomas) Assignee: Thomas Weidner (thomas) Tags: - Zend_Locale

Related issues: Attachments:


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.


Posted by Ben Scholzen (dasprid) on 2008-04-27T10:37:46.000+0000

What's the problem with my patch, Thomas?…

Posted by Thomas Weidner (thomas) on 2008-04-27T11:08:53.000+0000

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.

Posted by Wojciech Naruniec (wojciech) on 2008-06-17T14:46:47.000+0000

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.

Posted by Ben Scholzen (dasprid) on 2008-06-17T15:09:06.000+0000

That's exacly what my patch was doing.

Posted by Vincent de Lau (vdelau) on 2008-06-18T03:33:55.000+0000

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.

Posted by Vincent de Lau (vdelau) on 2008-06-18T04:03:03.000+0000

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

<pre class="highlight">
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);

Posted by Ben Scholzen (dasprid) on 2008-06-18T05:48:25.000+0000

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

Posted by Vincent de Lau (vdelau) on 2008-06-18T06:27:13.000+0000

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.

Posted by Thomas Weidner (thomas) on 2008-06-18T13:12:45.000+0000

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.

Posted by Thomas Weidner (thomas) on 2008-08-27T04:49:51.000+0000

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.

Posted by Wil Sinclair (wil) on 2008-09-02T10:38:50.000+0000

Updating for the 1.6.0 release.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.