|
From: Tor L. <tm...@ik...> - 2010-04-16 09:18:49
|
> Is there a way to convert this string into a POSIX compatible string ? > "French_France.1252" => "fr_FR.ISO8859-1 A small matter of programming;) Also, isn't it just so that using ISO639 language codes and ISO3166 country codes is a common convention in many implementations, not a standard? http://www.opengroup.org/onlinepubs/009695399/functions/setlocale.html says that "the contents of this string are implementation-defined". If you really need to know the "POSIX-style" equivalent of the C locale (which might be different from the Win32 thread locale in "exotic" or pathological cases), you need to resort to string comparisons, as far as I know. If knowing the "POSIX-style" equivalent of the Win32 thread locale is sufficient, the below code snippet might help. From GLib, so adapt as necessary. (This code snippet is written by me, and I hereby place it in the public domain.) This code snippet doesn't provide the character codeset part, so use something like sprintf(buf, "CP%d", GetACP()) for that. (GLib uses/requires UTF-8 everywhere, so there is no reason for this GLib function to provide the codeset part.) --tml gchar * g_win32_getlocale (void) { LCID lcid; LANGID langid; gchar *ev; gint primary, sub; char iso639[10]; char iso3166[10]; const gchar *script = NULL; /* Let the user override the system settings through environment * variables, as on POSIX systems. Note that in GTK+ applications * since GTK+ 2.10.7 setting either LC_ALL or LANG also sets the * Win32 locale and C library locale through code in gtkmain.c. */ if (((ev = getenv ("LC_ALL")) != NULL && ev[0] != '\0') || ((ev = getenv ("LC_MESSAGES")) != NULL && ev[0] != '\0') || ((ev = getenv ("LANG")) != NULL && ev[0] != '\0')) return g_strdup (ev); lcid = GetThreadLocale (); if (!GetLocaleInfo (lcid, LOCALE_SISO639LANGNAME, iso639, sizeof (iso639)) || !GetLocaleInfo (lcid, LOCALE_SISO3166CTRYNAME, iso3166, sizeof (iso3166))) return g_strdup ("C"); /* Strip off the sorting rules, keep only the language part. */ langid = LANGIDFROMLCID (lcid); /* Split into language and territory part. */ primary = PRIMARYLANGID (langid); sub = SUBLANGID (langid); /* Handle special cases */ switch (primary) { case LANG_AZERI: switch (sub) { case SUBLANG_AZERI_LATIN: script = "@Latn"; break; case SUBLANG_AZERI_CYRILLIC: script = "@Cyrl"; break; } break; case LANG_SERBIAN: /* LANG_CROATIAN == LANG_SERBIAN */ switch (sub) { case SUBLANG_SERBIAN_LATIN: case 0x06: /* Serbian (Latin) - Bosnia and Herzegovina */ script = "@Latn"; break; } break; case LANG_UZBEK: switch (sub) { case SUBLANG_UZBEK_LATIN: script = "@Latn"; break; case SUBLANG_UZBEK_CYRILLIC: script = "@Cyrl"; break; } break; } return g_strconcat (iso639, "_", iso3166, script, NULL); } |