summaryrefslogtreecommitdiff
path: root/gtk/gtkmain.c
diff options
context:
space:
mode:
authorTor Lillqvist <tml@novell.com>2006-10-10 21:51:11 +0000
committerTor Lillqvist <tml@src.gnome.org>2006-10-10 21:51:11 +0000
commitdcf4f2ef1e083443c8fe1069b21c0aa0c44e1237 (patch)
tree2bca7797c686414d340cd8a613af84aa652df637 /gtk/gtkmain.c
parentac1c7a0680e21e7771f520d549d32dfb9e6eaa92 (diff)
downloadgtk+-dcf4f2ef1e083443c8fe1069b21c0aa0c44e1237.tar.gz
Merge from 2.10 branch:
2006-10-11 Tor Lillqvist <tml@novell.com> Merge from 2.10 branch: * gtk/gtkmain.c (do_pre_parse_initialization): On Win32, if environment variable LC_ALL or LANG is set, set the Win32 thread locale to the corresponding locale. Then call the C library setlocale() to set the C library locale accordingly. The inconsistency mentioned below is gone. (#339756) Do some special casing for Serbia and Montenegro. Handle the Latin and Cyrillic scripts for Azeri, Uzbek and Serbian. (enum_locale_proc): Helper function for the above functionality. * gtk/gtkcalendar.c (gtk_calendar_init): No longer need to check if the environment variables are set here, as they have already been taken into account and the Win32 thread locale has been set.
Diffstat (limited to 'gtk/gtkmain.c')
-rw-r--r--gtk/gtkmain.c147
1 files changed, 147 insertions, 0 deletions
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 92af98a25f..8168e573b6 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -417,6 +417,95 @@ static const GOptionEntry gtk_args[] = {
{ NULL }
};
+#ifdef G_OS_WIN32
+
+static char *iso639_to_check = NULL;
+static char *iso3166_to_check = NULL;
+static char *script_to_check = NULL;
+static gboolean setlocale_called = FALSE;
+
+static BOOL CALLBACK
+enum_locale_proc (LPTSTR locale)
+{
+ LCID lcid;
+ char iso639[10];
+ char iso3166[10];
+ char *endptr;
+
+
+ lcid = strtoul (locale, &endptr, 16);
+ if (*endptr == '\0' &&
+ GetLocaleInfo (lcid, LOCALE_SISO639LANGNAME, iso639, sizeof (iso639)) &&
+ GetLocaleInfo (lcid, LOCALE_SISO3166CTRYNAME, iso3166, sizeof (iso3166)))
+ {
+ if (strcmp (iso639, iso639_to_check) == 0 &&
+ ((iso3166_to_check != NULL &&
+ strcmp (iso3166, iso3166_to_check) == 0) ||
+ (iso3166_to_check == NULL &&
+ SUBLANGID (LANGIDFROMLCID (lcid)) == SUBLANG_DEFAULT)))
+ {
+ char language[100], country[100];
+ char locale[300];
+
+ if (script_to_check != NULL)
+ {
+ /* If lcid is the "other" script for this language,
+ * return TRUE, i.e. continue looking.
+ */
+ if (strcmp (script_to_check, "Latn") == 0)
+ {
+ switch (LANGIDFROMLCID (lcid))
+ {
+ case MAKELANGID (LANG_AZERI, SUBLANG_AZERI_CYRILLIC):
+ return TRUE;
+ case MAKELANGID (LANG_UZBEK, SUBLANG_UZBEK_CYRILLIC):
+ return TRUE;
+ case MAKELANGID (LANG_SERBIAN, SUBLANG_SERBIAN_CYRILLIC):
+ return TRUE;
+ case MAKELANGID (LANG_SERBIAN, 0x07):
+ /* Serbian in Bosnia and Herzegovina, Cyrillic */
+ return TRUE;
+ }
+ }
+ else if (strcmp (script_to_check, "Cyrl") == 0)
+ {
+ switch (LANGIDFROMLCID (lcid))
+ {
+ case MAKELANGID (LANG_AZERI, SUBLANG_AZERI_LATIN):
+ return TRUE;
+ case MAKELANGID (LANG_UZBEK, SUBLANG_UZBEK_LATIN):
+ return TRUE;
+ case MAKELANGID (LANG_SERBIAN, SUBLANG_SERBIAN_LATIN):
+ return TRUE;
+ case MAKELANGID (LANG_SERBIAN, 0x06):
+ /* Serbian in Bosnia and Herzegovina, Latin */
+ return TRUE;
+ }
+ }
+ }
+
+ SetThreadLocale (lcid);
+
+ if (GetLocaleInfo (lcid, LOCALE_SENGLANGUAGE, language, sizeof (language)) &&
+ GetLocaleInfo (lcid, LOCALE_SENGCOUNTRY, country, sizeof (country)))
+ {
+ strcpy (locale, language);
+ strcat (locale, "_");
+ strcat (locale, country);
+
+ if (setlocale (LC_ALL, locale) != NULL)
+ setlocale_called = TRUE;
+ }
+
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+#endif
+
static void
do_pre_parse_initialization (int *argc,
char ***argv)
@@ -432,8 +521,66 @@ do_pre_parse_initialization (int *argc,
if (do_setlocale)
{
+#ifdef G_OS_WIN32
+ /* If some of the POSIXish environment variables are set, set
+ * the Win32 thread locale correspondingly.
+ */
+ char *p = getenv ("LC_ALL");
+ if (p == NULL)
+ p = getenv ("LANG");
+
+ if (p != NULL)
+ {
+ p = g_strdup (p);
+ if (strcmp (p, "C") == 0)
+ SetThreadLocale (LOCALE_SYSTEM_DEFAULT);
+ else
+ {
+ /* Check if one of the supported locales match the
+ * environment variable. If so, use that locale.
+ */
+ iso639_to_check = p;
+ iso3166_to_check = strchr (iso639_to_check, '_');
+ if (iso3166_to_check != NULL)
+ {
+ *iso3166_to_check++ = '\0';
+
+ script_to_check = strchr (iso3166_to_check, '@');
+ if (script_to_check != NULL)
+ *script_to_check++ = '\0';
+
+ /* Handle special cases. */
+
+ /* The standard code for Serbia and Montenegro was
+ * "CS", but MSFT uses for some reason "SP". By now
+ * (October 2006), SP has split into two, "RS" and
+ * "ME", but don't bother trying to handle those
+ * yet. Do handle the even older "YU", though.
+ */
+ if (strcmp (iso3166_to_check, "CS") == 0 ||
+ strcmp (iso3166_to_check, "YU") == 0)
+ iso3166_to_check = "SP";
+ }
+ else
+ {
+ script_to_check = strchr (iso639_to_check, '@');
+ if (script_to_check != NULL)
+ *script_to_check++ = '\0';
+ /* LANG_SERBIAN == LANG_CROATIAN, recognize just "sr" */
+ if (strcmp (iso639_to_check, "sr") == 0)
+ iso3166_to_check = "SP";
+ }
+
+ EnumSystemLocales (enum_locale_proc, LCID_SUPPORTED);
+ }
+ g_free (p);
+ }
+ if (!setlocale_called)
+ setlocale (LC_ALL, "");
+#else
if (!setlocale (LC_ALL, ""))
g_warning ("Locale not supported by C library.\n\tUsing the fallback 'C' locale.");
+#endif
}
gdk_pre_parse_libgtk_only ();