Description: Display names of days and months in the current language
Bug-Ubuntu: http://bugs.launchpad.net/bugs/1072019
Forwarded: https://bugzilla.gnome.org/show_bug.cgi?id=687945
Author: Gunnar Hjalmarsson <gunnarhj@ubuntu.com>
Last-Update: 2012-11-07

*
* NOTE: The status of this patch is work-in-progress. It's a
* quick-and-dirty attempt at a fix, but does not work as expected.
*

Index: glib2.0-2.34.1/glib/gdatetime.c
===================================================================
--- glib2.0-2.34.1.orig/glib/gdatetime.c	2012-08-17 06:18:08.000000000 +0200
+++ glib2.0-2.34.1/glib/gdatetime.c	2012-11-07 15:29:45.161010232 +0100
@@ -2167,6 +2167,25 @@
   return success;
 }
 
+/* g_date_time_format() subroutine that sets LC_TIME using the
+ * LC_MESSAGES locale. Applicable to the %a, %A, %b, %B, and %h
+ * conversion specifications, i.e. names of days and months.
+ */
+static gchar *
+g_date_time_set_locale_for_language ()
+{
+  gchar *time_locale;
+
+  time_locale = g_strdup (setlocale (LC_TIME, NULL));
+  const gchar *message_locale = setlocale (LC_MESSAGES, NULL);
+  const gchar *lc_msg_env = setlocale (LC_MESSAGES, "");
+  setlocale (LC_MESSAGES, message_locale);
+
+  setlocale (LC_TIME, lc_msg_env);
+
+  return time_locale;
+}
+
 /* g_date_time_format() subroutine that takes a UTF-8 format
  * string and produces a locale-encoded date/time string.
  */
@@ -2183,6 +2202,7 @@
   gboolean  pad_set = FALSE;
   gchar    *pad = "";
   gchar    *ampm;
+  gchar    *time_locale;
   const gchar *tz;
 
   while (*format)
@@ -2220,16 +2240,24 @@
       switch (c)
 	{
 	case 'a':
+	  time_locale = g_date_time_set_locale_for_language ();
 	  g_string_append (outstr, WEEKDAY_ABBR (datetime));
+	  setlocale (LC_TIME, time_locale);
 	  break;
 	case 'A':
+	  time_locale = g_date_time_set_locale_for_language ();
 	  g_string_append (outstr, WEEKDAY_FULL (datetime));
+	  setlocale (LC_TIME, time_locale);
 	  break;
 	case 'b':
+	  time_locale = g_date_time_set_locale_for_language ();
 	  g_string_append (outstr, MONTH_ABBR (datetime));
+	  setlocale (LC_TIME, time_locale);
 	  break;
 	case 'B':
+	  time_locale = g_date_time_set_locale_for_language ();
 	  g_string_append (outstr, MONTH_FULL (datetime));
+	  setlocale (LC_TIME, time_locale);
 	  break;
 	case 'c':
 	  {
@@ -2265,7 +2293,9 @@
 			 g_date_time_get_week_numbering_year (datetime));
 	  break;
 	case 'h':
+	  time_locale = g_date_time_set_locale_for_language ();
 	  g_string_append (outstr, MONTH_ABBR (datetime));
+	  setlocale (LC_TIME, time_locale);
 	  break;
 	case 'H':
 	  format_number (outstr, alt_digits, pad_set ? pad : "0", 2,

