Description: Display time on the greeter in accordance with the system wide settings in Language Support.
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=651506
Bug-Ubuntu: https://launchpad.net/bugs/777264
Forwarded: yes
Author: Gunnar Hjalmarsson <ubuntu@gunnar.cc>

diff -Nur -x '*.orig' -x '*~' gdm-2.32.1//gui/simple-greeter/gdm-clock-widget.c gdm-2.32.1.new//gui/simple-greeter/gdm-clock-widget.c
--- gdm-2.32.1//gui/simple-greeter/gdm-clock-widget.c	2011-06-08 02:08:41.368077000 +0200
+++ gdm-2.32.1.new//gui/simple-greeter/gdm-clock-widget.c	2011-06-08 05:51:13.283555424 +0200
@@ -30,6 +30,8 @@
 #include <errno.h>
 #include <dirent.h>
 #include <sys/stat.h>
+#include <locale.h>
+#include <langinfo.h>
 
 #include <glib.h>
 #include <glib/gi18n.h>
@@ -57,53 +59,40 @@
 
 G_DEFINE_TYPE (GdmClockWidget, gdm_clock_widget, GTK_TYPE_ALIGNMENT)
 
+int
+is_24h ()
+{
+        static const char *formats_24h[] = {"%H", "%R", "%T", "%OH", "%k", NULL};
+        const char        *t_fmt = nl_langinfo(T_FMT);
+        int                i;
+
+        for (i = 0; formats_24h[i]; ++i) {
+                if (strstr(t_fmt, formats_24h[i])) {
+                        return 1;
+                }
+        }
+        return 0;
+}
+
 static void
 update_time_format (GdmClockWidget *clock)
 {
         char       *clock_format;
         char       *tooltip_format;
 
-        if (clock->priv->should_show_date && clock->priv->should_show_seconds) {
-                /* translators: This is the time format to use when both
-                 * the date and time with seconds are being shown together.
-                 */
-                clock_format = _("%a %b %e, %l:%M:%S %p");
-                tooltip_format = NULL;
-        } else if (clock->priv->should_show_date && !clock->priv->should_show_seconds) {
-                /* translators: This is the time format to use when both
-                 * the date and time without seconds are being shown together.
-                 */
-                clock_format = _("%a %b %e, %l:%M %p");
-
-                tooltip_format = NULL;
-        } else if (!clock->priv->should_show_date && clock->priv->should_show_seconds) {
-                /* translators: This is the time format to use when there is
-                 * no date, just weekday and time with seconds.
-                 */
-                clock_format = _("%a %l:%M:%S %p");
-
-                /* translators: This is the time format to use for the date
-                 */
-                tooltip_format = "%x";
+        setlocale(LC_TIME, "");
+        if ( is_24h() ) {
+                clock_format = "%H:%M";
         } else {
-                /* translators: This is the time format to use when there is
-                 * no date, just weekday and time without seconds.
-                 */
-                clock_format = _("%a %l:%M %p");
-
-                tooltip_format = "%x";
+                clock_format = "%l:%M %p";
         }
+        tooltip_format = "%x";
 
         g_free (clock->priv->time_format);
         clock->priv->time_format = g_locale_from_utf8 (clock_format, -1, NULL, NULL, NULL);
 
         g_free (clock->priv->tooltip_format);
-
-        if (tooltip_format != NULL) {
-                clock->priv->tooltip_format = g_locale_from_utf8 (tooltip_format, -1, NULL, NULL, NULL);
-        } else {
-                clock->priv->tooltip_format = NULL;
-        }
+        clock->priv->tooltip_format = g_locale_from_utf8 (tooltip_format, -1, NULL, NULL, NULL);
 }
 
 static void
@@ -113,6 +102,8 @@
 {
         time_t     t;
         struct tm *tm;
+        char       showed_time[32];
+        char       weekday[32];
         char       buf[256];
         char      *utf8;
 
@@ -122,15 +113,21 @@
                 g_warning ("Unable to get broken down local time");
                 return;
         }
-        if (strftime (buf, sizeof (buf), clock_format, tm) == 0) {
+        if (strftime (showed_time, sizeof (showed_time), clock_format, tm) == 0) {
                 g_warning ("Couldn't format time: %s", clock_format);
-                strcpy (buf, "???");
+                strcpy (showed_time, "???");
         }
+
+        setlocale( LC_TIME, getenv("LC_MESSAGES") );
+        strftime(weekday, sizeof(weekday), "%a", tm);
+        sprintf(buf, "%s %s", weekday, showed_time);
+
         utf8 = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
         gtk_label_set_text (label, utf8);
         g_free (utf8);
 
         if (tooltip_format != NULL) {
+                setlocale(LC_TIME, "");
                 if (strftime (buf, sizeof (buf), tooltip_format, tm) == 0) {
                         g_warning ("Couldn't format tooltip date: %s", tooltip_format);
                         strcpy (buf, "???");
