[gnome-desktop] languages: Use a more broadly compatible locale codeset suffix
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-desktop] languages: Use a more broadly compatible locale codeset suffix
- Date: Wed, 29 Oct 2014 14:05:46 +0000 (UTC)
commit 093e0a549c2ab2e465494105126ea7046f26e047
Author: Rui Matos <tiagomatos gmail com>
Date: Mon Jan 20 22:38:10 2014 +0100
languages: Use a more broadly compatible locale codeset suffix
At least OpenBSD's libc doesn't accept 'utf8' as a locale codeset
suffix but does accept 'UTF-8'. Since GNU libc accepts both suffixes
let's use the one which works on a broader set of systems.
Thanks to Stefan Sperling and Antoine Jacoutot.
https://bugzilla.gnome.org/show_bug.cgi?id=710412
libgnome-desktop/gnome-languages.c | 37 +++++++++++++++--------------------
1 files changed, 16 insertions(+), 21 deletions(-)
---
diff --git a/libgnome-desktop/gnome-languages.c b/libgnome-desktop/gnome-languages.c
index 6a18eba..5e9a2f3 100644
--- a/libgnome-desktop/gnome-languages.c
+++ b/libgnome-desktop/gnome-languages.c
@@ -88,27 +88,14 @@ gnome_locale_free (GnomeLocale *locale)
static char *
normalize_codeset (const char *codeset)
{
- char *normalized_codeset;
- const char *p;
- char *q;
-
- normalized_codeset = g_strdup (codeset);
-
- if (codeset != NULL) {
- for (p = codeset, q = normalized_codeset;
- *p != '\0'; p++) {
-
- if (*p == '-' || *p == '_') {
- continue;
- }
+ if (codeset == NULL)
+ return NULL;
- *q = g_ascii_tolower (*p);
- q++;
- }
- *q = '\0';
- }
+ if (g_str_equal (codeset, "UTF-8") ||
+ g_str_equal (codeset, "utf8"))
+ return g_strdup ("UTF-8");
- return normalized_codeset;
+ return g_strdup (codeset);
}
/**
@@ -340,7 +327,7 @@ language_name_get_codeset_details (const char *language_name,
if (is_utf8 != NULL) {
codeset = normalize_codeset (codeset);
- *is_utf8 = strcmp (codeset, "utf8") == 0;
+ *is_utf8 = strcmp (codeset, "UTF-8") == 0;
g_free (codeset);
}
@@ -411,7 +398,15 @@ add_locale (const char *language_name,
if (is_utf8) {
name = g_strdup (language_name);
} else if (utf8_only) {
- name = g_strdup_printf ("%s.utf8", language_name);
+
+ if (strchr (language_name, '.'))
+ return FALSE;
+
+ /* If the locale name has no dot, assume that its
+ * encoding part is missing and try again after adding
+ * ".UTF-8". This catches locale names like "de_DE".
+ */
+ name = g_strdup_printf ("%s.UTF-8", language_name);
language_name_get_codeset_details (name, NULL, &is_utf8);
if (!is_utf8) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]