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-12

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-12 06:48:24.218161549 +0100
@@ -2167,6 +2167,36 @@
   return success;
 }
 
+/* g_date_time_format() subroutine that makes the LC_MESSAGES locale
+ * be used when replacing a conversion specification. Applicable to
+ * %a, %A, %b, %B, and %h, i.e. names of days and months.
+ */
+static void
+g_date_time_use_locale_for_language ()
+{
+  static locale_t locale_obj;
+  static gboolean is_warning = FALSE;
+
+  if (is_warning)
+    return;
+
+  if (!locale_obj) {
+    const gchar *lang_locale = getenv ("LC_ALL");
+    if (lang_locale == NULL)
+      lang_locale = getenv ("LC_MESSAGES");
+    if (lang_locale == NULL)
+      lang_locale = getenv ("LANG");
+    if (lang_locale == NULL) {
+      g_warning ("Neither LC_MESSAGES nor LANG set -- using the program's global locale");
+      is_warning = TRUE;
+      return;
+    }
+    locale_obj = newlocale (LC_TIME_MASK, lang_locale, NULL);
+  }
+
+  uselocale (locale_obj);
+}
+
 /* g_date_time_format() subroutine that takes a UTF-8 format
  * string and produces a locale-encoded date/time string.
  */
@@ -2220,16 +2250,24 @@
       switch (c)
 	{
 	case 'a':
+	  g_date_time_use_locale_for_language ();
 	  g_string_append (outstr, WEEKDAY_ABBR (datetime));
+	  uselocale (LC_GLOBAL_LOCALE);
 	  break;
 	case 'A':
+	  g_date_time_use_locale_for_language ();
 	  g_string_append (outstr, WEEKDAY_FULL (datetime));
+	  uselocale (LC_GLOBAL_LOCALE);
 	  break;
 	case 'b':
+	  g_date_time_use_locale_for_language ();
 	  g_string_append (outstr, MONTH_ABBR (datetime));
+	  uselocale (LC_GLOBAL_LOCALE);
 	  break;
 	case 'B':
+	  g_date_time_use_locale_for_language ();
 	  g_string_append (outstr, MONTH_FULL (datetime));
+	  uselocale (LC_GLOBAL_LOCALE);
 	  break;
 	case 'c':
 	  {
@@ -2265,7 +2303,9 @@
 			 g_date_time_get_week_numbering_year (datetime));
 	  break;
 	case 'h':
+	  g_date_time_use_locale_for_language ();
 	  g_string_append (outstr, MONTH_ABBR (datetime));
+	  uselocale (LC_GLOBAL_LOCALE);
 	  break;
 	case 'H':
 	  format_number (outstr, alt_digits, pad_set ? pad : "0", 2,
@@ -2472,28 +2512,32 @@
  * many formats is locale-dependent and may not match the strftime()
  * output exactly.
  *
+ * Also, unlike strftime(), this function replaces conversions for names
+ * of weekdays and months using the locale of the environment variable
+ * that determines the display language for menus and messages.
+ *
  * The following format specifiers are supported:
  *
  * <variablelist>
  *  <varlistentry><term>
  *    <literal>\%a</literal>:
  *   </term><listitem><simpara>
- *    the abbreviated weekday name according to the current locale
+ *    the abbreviated weekday name according to the locale for the display language
  *  </simpara></listitem></varlistentry>
  *  <varlistentry><term>
  *    <literal>\%A</literal>:
  *   </term><listitem><simpara>
- *    the full weekday name according to the current locale
+ *    the full weekday name according to the locale for the display language
  *  </simpara></listitem></varlistentry>
  *  <varlistentry><term>
  *    <literal>\%b</literal>:
  *   </term><listitem><simpara>
- *    the abbreviated month name according to the current locale
+ *    the abbreviated month name according to the locale for the display language
  *  </simpara></listitem></varlistentry>
  *  <varlistentry><term>
  *    <literal>\%B</literal>:
  *   </term><listitem><simpara>
- *    the full month name according to the current locale
+ *    the full month name according to the locale for the display language
  *  </simpara></listitem></varlistentry>
  *  <varlistentry><term>
  *    <literal>\%c</literal>:

