[i18n] [Patch] Localization problems with strftime

Thierry Thomas thierry@pompo.net
Tue, 6 Aug 2002 02:03:49 +0200


Hello,

On some platforms (e.g. FreeBSD), strftime is not localized if setlocale
is not set. For example IMP, Kronolith, Nag, etc. show un-localized
dates.

The following patches fix this problem for me - and I hope they do not
break anything!

1) For Horde's Summary:

--- lib/base.php.orig	Sat Jul 27 22:07:21 2002
+++ lib/base.php	Tue Aug  6 01:31:59 2002
@@ -41,5 +41,12 @@
 require_once HORDE_BASE . '/lib/Notification.php';
 $notification = &Notification::singleton();
 $notification->attach('status');
+ 
+// Force setlocale
+$charset = NLS::getCharset();
+$pos = strpos($charset, '-');
+if (!($pos === FALSE)) {
+    setlocale(LC_TIME, $language . "." . substr($charset, 0, $pos) . substr($charset, $pos + 1));
+}
 
 ?>


2) For IMP:

--- imp/lib/base.php.orig	Fri Aug  2 22:29:08 2002
+++ imp/lib/base.php	Tue Aug  6 01:44:17 2002
@@ -74,5 +74,12 @@
 if ($authentication !== 'none') {
     IMP::checkAuthentication($authentication);
 }
+ 
+// Force setlocale
+$charset = NLS::getCharset();
+$pos = strpos($charset, '-');
+if (!($pos === FALSE) && isset($language)) {
+    setlocale(LC_TIME, $language . "." . substr($charset, 0, $pos) . substr($charset, $pos + 1));
+}
 
 ?>


3) For Kronolith:


--- kronolith/lib/base.php.orig	Fri Aug  2 22:31:05 2002
+++ kronolith/lib/base.php	Tue Aug  6 01:48:23 2002
@@ -57,6 +57,13 @@
 // Set the timezone variable, if available.
 NLS::setTimeZone();
 
+// Force setlocale
+$charset = NLS::getCharset();
+$pos = strpos($charset, '-');
+if (!($pos === FALSE) && isset($language)) {
+    setlocale(LC_TIME, $language . "." . substr($charset, 0, $pos) . substr($charset, $pos + 1));
+}
+
 // Open the users calendar
 $GLOBALS['calendar'] = &Kronolith_Driver::factory($conf['calendar']['driver'], $conf['calendar']['params']);
 $GLOBALS['calendar']->open(Auth::getAuth());


I am interested by your comments. Of course, if it works for any
platform / language, we could write a global function and call it from
every module.

Best regards,
-- 
Th. Thomas.