summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Cameron <brian.cameron@sun.com>2006-12-29 08:41:09 +0000
committerBrian Cameron <bcameron@src.gnome.org>2006-12-29 08:41:09 +0000
commit4d102692e81bfff9f2950136b2abe4cd6724d96b (patch)
tree3217768b5cfb57f9265e1e3102dbc1c9625d501b
parent9bfc7c4aafc4716b659e6ef0690d20e1d10afa56 (diff)
downloadgdm-4d102692e81bfff9f2950136b2abe4cd6724d96b.tar.gz
Now GDM will recognize when the system language has changed and when new
2006-12-29 Brian Cameron <brian.cameron@sun.com> * configure.ac, daemon/Makefile.am, daemon/misc.[ch], daemon/slave.c, daemon/verify-pam.c: Now GDM will recognize when the system language has changed and when new GUI's are displayed they will be in the new system language without neeting to restart GDM. By default the /var/sysconfig/i18n file is assumed to have the language defined in LANG=foo format. The --with-lang-file configure option may be needed to specify a different system language configuration file. On Solaris it would be /etc/default/init, for example. Note the change to verify-pam is done to flush the hash table of pam messages to useful translations. This change implements enhancement request #384603. Patch by Ray Strode <rstrode@redhat.com> and Takao Fujiwara <Takao.Fujiwara@sun.com>.
-rw-r--r--ChangeLog16
-rw-r--r--configure.ac15
-rw-r--r--daemon/Makefile.am1
-rw-r--r--daemon/misc.c84
-rw-r--r--daemon/misc.h1
-rw-r--r--daemon/slave.c5
-rw-r--r--daemon/verify-pam.c14
7 files changed, 136 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 7c35f7b8..31476431 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2006-12-29 Brian Cameron <brian.cameron@sun.com>
+
+ * configure.ac, daemon/Makefile.am, daemon/misc.[ch],
+ daemon/slave.c, daemon/verify-pam.c: Now GDM will recognize
+ when the system language has changed and when new GUI's are
+ displayed they will be in the new system language without
+ neeting to restart GDM. By default the /var/sysconfig/i18n
+ file is assumed to have the language defined in LANG=foo format.
+ The --with-lang-file configure option may be needed to specify
+ a different system language configuration file. On Solaris
+ it would be /etc/default/init, for example. Note the change
+ to verify-pam is done to flush the hash table of pam messages
+ to useful translations. This change implements enhancement
+ request #384603. Patch by Ray Strode <rstrode@redhat.com>
+ and Takao Fujiwara <Takao.Fujiwara@sun.com>.
+
2006-12-21 Lukasz Zalewski <lukas@dcs.qmul.ac.uk>
* More fixes/changes for bug/feature request #334186.
diff --git a/configure.ac b/configure.ac
index 34282fac..09b2250b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -116,6 +116,21 @@ else
fi
AC_SUBST(PAM_PREFIX)
+dnl
+dnl file that sets LANG
+dnl
+withval=""
+AC_ARG_WITH(lang-file,
+ [ --with-lang-file=<filename> file containing default language setting],[
+if test x$withval != x; then
+AC_MSG_RESULT("System locale will be looked for in file ${withval}.")
+fi])
+if test x$withval != x; then
+ LANG_CONFIG_FILE="$withval"
+else
+ LANG_CONFIG_FILE='${sysconfdir}/sysconfig/i18n'
+fi
+AC_SUBST(LANG_CONFIG_FILE)
AC_PATH_PROG(CONSOLE_HELPER,consolehelper,no)
if test "x$CONSOLE_HELPER" = "xno" ; then
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index d99e3580..b34261b1 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -24,6 +24,7 @@ INCLUDES = \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
$(GUI_CFLAGS) \
$(DAEMON_CFLAGS) \
+ -DLANG_CONFIG_FILE=\"$(LANG_CONFIG_FILE)\" \
-DPAM_PREFIX=\"$(PAM_PREFIX)\" \
$(GNOME_INCLUDEDIR) \
-DGREETERTHEMEDIR=\""$(datadir)/gdm/themes"\"
diff --git a/daemon/misc.c b/daemon/misc.c
index 3dc42d43..a1918700 100644
--- a/daemon/misc.c
+++ b/daemon/misc.c
@@ -2145,6 +2145,90 @@ gdm_reset_limits (void)
}
}
+#define CHECK_LC(value, category) \
+ (g_str_has_prefix (line->str, value "=")) \
+ { \
+ character = g_utf8_get_char (line->str + strlen (value "=")); \
+\
+ if ((character == '\'') || (character == '\"')) \
+ { \
+ q = g_utf8_find_prev_char (line->str, line->str + line->len); \
+\
+ if ((q == NULL) || (g_utf8_get_char (q) != character)) \
+ { \
+ g_string_set_size (line, 0); \
+ continue; \
+ } \
+\
+ g_string_set_size (line, line->len - 1); \
+ g_setenv (value, line->str + strlen (value "=") + 1, TRUE); \
+ if (category) \
+ setlocale ((category), line->str + strlen (value "=") + 1); \
+ } \
+ else \
+ { \
+ g_setenv (value, line->str + strlen (value "="), TRUE); \
+ if (category) \
+ setlocale ((category), line->str + strlen (value "=")); \
+ } \
+\
+ g_string_set_size (line, 0); \
+ continue; \
+ }
+
+void
+gdm_reset_locale (void)
+{
+ char *i18n_file_contents;
+ gsize i18n_file_length, i;
+ GString *line;
+ const gchar *p, *q;
+
+ i18n_file_contents = NULL;
+ line = NULL;
+ p = NULL;
+ if (!g_file_get_contents (LANG_CONFIG_FILE, &i18n_file_contents,
+ &i18n_file_length, NULL))
+ goto out;
+
+ if (!g_utf8_validate (i18n_file_contents, i18n_file_length, NULL))
+ goto out;
+
+ line = g_string_new ("");
+ p = i18n_file_contents;
+ for (i = 0; i < i18n_file_length;
+ p = g_utf8_next_char (p), i = p - i18n_file_contents)
+ {
+ gunichar character;
+ character = g_utf8_get_char (p);
+
+ if ((character != '\n') && (character != '\0'))
+ {
+ g_string_append_unichar (line, character);
+ continue;
+ }
+
+ if CHECK_LC("LC_ALL", LC_ALL)
+ else if CHECK_LC("LC_COLLATE", LC_COLLATE)
+ else if CHECK_LC("LC_MESSAGES", LC_MESSAGES)
+ else if CHECK_LC("LC_MONETARY", LC_MONETARY)
+ else if CHECK_LC("LC_NUMERIC", LC_NUMERIC)
+ else if CHECK_LC("LC_TIME", LC_TIME)
+ else if CHECK_LC("LANG", NULL)
+
+ g_string_set_size (line, 0);
+ }
+
+ g_string_free (line, TRUE);
+
+ setlocale (LC_ALL, "");
+
+ out:
+ g_free (i18n_file_contents);
+}
+
+#undef CHECK_LC(value, category)
+
#else /* ! NUM_OF_LIMITS */
/* We have to go one by one here */
diff --git a/daemon/misc.h b/daemon/misc.h
index 33a4d2c1..51edb497 100644
--- a/daemon/misc.h
+++ b/daemon/misc.h
@@ -142,6 +142,7 @@ FILE * gdm_safe_fopen_ap (const char *file);
limits */
void gdm_get_initial_limits (void);
void gdm_reset_limits (void);
+void gdm_reset_locale (void);
const char *gdm_root_user (void);
diff --git a/daemon/slave.c b/daemon/slave.c
index e4006f25..143b189b 100644
--- a/daemon/slave.c
+++ b/daemon/slave.c
@@ -1309,6 +1309,8 @@ gdm_slave_run (GdmDisplay *display)
gint maxtries = 0;
gint pinginterval = gdm_get_value_int (GDM_KEY_PING_INTERVAL);
+ gdm_reset_locale ();
+
/* Reset d since gdm_slave_run is called in a loop */
d = display;
@@ -1758,6 +1760,7 @@ run_config (GdmDisplay *display, struct passwd *pwent)
/* setup environment */
gdm_restoreenv ();
+ gdm_reset_locale ();
/* root here */
g_setenv ("XAUTHORITY", GDM_AUTHFILE (display), TRUE);
@@ -2519,6 +2522,7 @@ gdm_slave_greeter (void)
"gdm_slave_greeter", gdm_get_gdmuid ());
gdm_restoreenv ();
+ gdm_reset_locale ();
g_setenv ("XAUTHORITY", GDM_AUTHFILE (d), TRUE);
g_setenv ("DISPLAY", d->name, TRUE);
@@ -3020,6 +3024,7 @@ gdm_slave_chooser (void)
"gdm_slave_chooser", gdm_get_gdmuid ());
gdm_restoreenv ();
+ gdm_reset_locale ();
g_setenv ("XAUTHORITY", GDM_AUTHFILE (d), TRUE);
g_setenv ("DISPLAY", d->name, TRUE);
diff --git a/daemon/verify-pam.c b/daemon/verify-pam.c
index 8c0ffaa2..842d5b53 100644
--- a/daemon/verify-pam.c
+++ b/daemon/verify-pam.c
@@ -417,7 +417,21 @@ perhaps_translate_message (const char *msg)
char *s;
const char *ret;
static GHashTable *hash = NULL;
+ static char *locale = NULL;
+
+ /* if locale changes out from under us then rebuild hash table
+ */
+ if ((locale != NULL) &&
+ (strcmp (locale, setlocale (LC_ALL, NULL)) != 0)) {
+ g_assert (hash != NULL);
+ g_hash_table_destroy (hash);
+ hash = NULL;
+ }
+
if (hash == NULL) {
+ g_free (locale);
+ locale = g_strdup (setlocale (LC_ALL, NULL));
+
/* Here we come with some fairly standard messages so that
we have as much as possible translated. Should really be
translated in pam I suppose. This way we can "change"