Re: Dates and l10n



I originally posted this to the gnome list:
On Sun, Nov 28 1999, at 22:37:31 +0200, Bjorn Andersson wrote:
> Do l10n and dates currently not work in Gnome, or am I doing something
> wrong? I have tried setting both LC_ALL and LC_TIME to finnish as well
> as swedish, but at least gnomecal, gnumeric and the DateTime widget
> in general do not format the short date correctly. It is always
> shown as mm/dd/yyyy. How do I get it to be formated as dd.mm.yyyy
> or yyyy-mm-dd? In gnumeric 0.44 when I insert "current date", I get
> '//' and 'mm/dd/' for finnish and swedish respecively. Is this a bug?

Above I was talking about the DateEdit widget (not DateTime). I
took a look at the file gnome-dateedit.c and indeed it hade
comments and code like the following:
 /* FIXME: internationalize this - strftime()*/
 g_snprintf (buffer, sizeof(buffer), "%d/%d/%d", month + 1, day, year);

I will attach a suggestion for a patch against gnome-libs-1.0.54 to
the i18n related FIXMEs in gnome-dateedit.c.

Pablo Saratxaga notified me that the gnumeric problem was due to
improper .po files. I took a look at the gnumeric code, to see how
date formatting is done. Why don't we just use the same format as
strftime does, and use strftime to do the formatting? Then it would
automatically be bound to the locale (as specified with LC_TIME)
without having to do translations in the gnuermic .po files (which
would be translated according to the LC_MESSAGE variable).

Best regards,
Björn

-- 
Björn Andersson  <bjorn@lifix.fi>                        +358-50-3412556
Lifix Systems Oy <http://www.lifix.fi/>     Professional Linux Solutions
Tekniikantie 21, FIN-02150 Espoo                          +358-9-4375272
--- gnome-libs-1.0.54.orig/libgnomeui/gnome-dateedit.c	Wed Oct 20 15:46:06 1999
+++ gnome-libs-1.0.54/libgnomeui/gnome-dateedit.c	Mon Nov 29 19:02:30 1999
@@ -75,11 +75,16 @@
 {
 	char buffer [40];
 	gint year, month, day;
+	struct tm tm = {0};
 
 	gtk_calendar_get_date (calendar, &year, &month, &day);
-
-	/* FIXME: internationalize this - strftime()*/
-	g_snprintf (buffer, sizeof(buffer), "%d/%d/%d", month + 1, day, year);
+	if (tm.tm_year >= 1900) 
+		tm.tm_year = year - 1900;
+	else 
+		tm.tm_year = year;
+	tm.tm_mon = month;
+	tm.tm_mday = day;
+	strftime(buffer, sizeof(buffer), "%x", &tm);
 	gtk_entry_set_text (GTK_ENTRY (gde->date_entry), buffer);
 	gtk_signal_emit (GTK_OBJECT (gde), date_edit_signals [DATE_CHANGED]);
 }
@@ -177,16 +182,8 @@
 	GdkCursor *cursor;
 
         /* This code is pretty much just copied from gtk_date_edit_get_date */
-      	sscanf (gtk_entry_get_text (GTK_ENTRY (gde->date_entry)), "%d/%d/%d",
-		&mtm.tm_mon, &mtm.tm_mday, &mtm.tm_year); /* FIXME: internationalize this - strptime()*/
-        
-        mtm.tm_mon--;
-
-	/* Hope the user does not actually mean years early in the A.D. days...
-	 * This date widget will obviously not work for a history program :-)
-	 */
-	if (mtm.tm_year >= 1900)
-		mtm.tm_year -= 1900;
+	strptime(gtk_entry_get_text (GTK_ENTRY (gde->date_entry)), "%x",
+			&mtm);
 
 	gtk_calendar_select_month (GTK_CALENDAR (gde->calendar), mtm.tm_mon, 1900 + mtm.tm_year);
         gtk_calendar_select_day (GTK_CALENDAR (gde->calendar), mtm.tm_mday);
@@ -394,10 +391,7 @@
 	mytm = localtime (&the_time);
 
 	/* Set the date */
-	g_snprintf (buffer, sizeof(buffer), "%d/%d/%d",
-		    mytm->tm_mon + 1,
-		    mytm->tm_mday,
-		    1900 + mytm->tm_year);
+	strftime(buffer, sizeof(buffer), "%x", mytm);
 	gtk_entry_set_text (GTK_ENTRY (gde->date_entry), buffer);
 
 	/* Set the time */
@@ -573,16 +567,7 @@
 	g_assert(gde != NULL);
 	g_assert(GNOME_IS_DATE_EDIT(gde));
 	
-	sscanf (gtk_entry_get_text (GTK_ENTRY (gde->date_entry)), "%d/%d/%d",
-		&tm.tm_mon, &tm.tm_mday, &tm.tm_year); /* FIXME: internationalize this - strptime()*/
-
-	tm.tm_mon--;
-
-	/* Hope the user does not actually mean years early in the A.D. days...
-	 * This date widget will obviously not work for a history program :-)
-	 */
-	if (tm.tm_year >= 1900)
-		tm.tm_year -= 1900;
+	strptime(gtk_entry_get_text (GTK_ENTRY (gde->date_entry)), "%x", &tm);
 
 	if (gde->flags & GNOME_DATE_EDIT_SHOW_TIME) {
 		char *tokp, *temp;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]