[accounts-dialog] Set the current language from the locale if not set



commit 2c6400a01424a039f6c636c32ef72453b0c2b88f
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Jan 13 13:08:34 2010 +0000

    Set the current language from the locale if not set

 src/main.c |   56 +++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 35 insertions(+), 21 deletions(-)
---
diff --git a/src/main.c b/src/main.c
index 8643165..162e980 100644
--- a/src/main.c
+++ b/src/main.c
@@ -369,13 +369,27 @@ show_user (UmUser *user, UserAccountDialog *d)
 
         label = get_widget (d, "account-language-value-label");
         text = um_user_get_language (user);
-        if (text && text[0] != 0) {
+        if (text) {
                 language = gdm_get_language_from_name (text, NULL);
                 gtk_label_set_text (GTK_LABEL (label), language);
                 g_free (language);
         }
         else {
-                gtk_label_set_text (GTK_LABEL (label), "-");
+                const char *locale;
+
+                locale = (const char *) setlocale(LC_MESSAGES, NULL);
+                if (locale) {
+                        char *name;
+
+                        name = gdm_normalize_language_name (locale);
+                        language = gdm_get_language_from_name (name, NULL);
+                        g_free (name);
+
+                        gtk_label_set_text (GTK_LABEL (label), language);
+                        g_free (language);
+                } else {
+                        gtk_label_set_text (GTK_LABEL (label), "-");
+                }
         }
 
         label = get_widget (d, "account-location-value-label");
@@ -729,43 +743,43 @@ main (int argc, char *argv[])
         GError *error;
         const gchar *filename;
         GtkWidget *dialog;
-	GOptionContext *context;
+        GOptionContext *context;
         static gboolean do_debug;
         static gboolean do_version;
         static GOptionEntry entries[] = {
-		{ "debug", 0, 0, G_OPTION_ARG_NONE, &do_debug, N_("Enable debugging code"), NULL },
+                { "debug", 0, 0, G_OPTION_ARG_NONE, &do_debug, N_("Enable debugging code"), NULL },
                 { "version", 0, 0, G_OPTION_ARG_NONE, &do_version, N_("Output version information and exit"), NULL },
                 { NULL }
-	};
+        };
 
         setlocale (LC_ALL, "");
         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
         g_thread_init (NULL);
 
-	context = g_option_context_new ("");
+        context = g_option_context_new ("");
         g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
         g_option_context_set_summary (context, _("Lets you edit user account information."));
         g_option_context_add_main_entries (context, entries, NULL);
-	g_option_context_add_group (context, gtk_get_option_group (TRUE));
-	error = NULL;
+        g_option_context_add_group (context, gtk_get_option_group (TRUE));
+        error = NULL;
         if (!g_option_context_parse (context, &argc, &argv, &error)) {
-		g_warning ("%s", error->message);
-		g_error_free (error);
-		exit (1);
-	}
+                g_warning ("%s", error->message);
+                g_error_free (error);
+                exit (1);
+        }
         g_option_context_free (context);
 
-	if (do_version) {
-		g_print ("accounts-dialog " VERSION "\n");
-		exit (0);
-	}
+        if (do_version) {
+                g_print ("accounts-dialog " VERSION "\n");
+                exit (0);
+        }
 
-	if (!do_debug) {
-        	g_log_set_handler (NULL,
-                           	   G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO,
-                           	   eat_my_logs, NULL);
-	}
+        if (!do_debug) {
+                g_log_set_handler (NULL,
+                                      G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO,
+                                      eat_my_logs, NULL);
+        }
 
         d = g_new0 (UserAccountDialog, 1);
 



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