summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Matos <tiagomatos@gmail.com>2016-02-09 18:11:58 +0100
committerRui Matos <tiagomatos@gmail.com>2016-02-15 17:45:17 +0100
commit104fb3d9397d7834762cf3b49e01c3f80d69af49 (patch)
tree047dfc5230ca8aa664272212ff7e4cd67f415724
parent389a3761cf70b20be40894ce3dbb2e81b25a1a79 (diff)
downloadgnome-desktop-104fb3d9397d7834762cf3b49e01c3f80d69af49.tar.gz
gnome-languages: Capitalize language and territory names
Translations in iso-codes are inconsistent in their capitalization of language and territory names. That's not under our control, but we can automatically capitalize them since that's how our API consumers expect them to be. https://bugzilla.gnome.org/show_bug.cgi?id=761776
-rw-r--r--libgnome-desktop/gnome-languages.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/libgnome-desktop/gnome-languages.c b/libgnome-desktop/gnome-languages.c
index ec23a7a8..cbf82d33 100644
--- a/libgnome-desktop/gnome-languages.c
+++ b/libgnome-desktop/gnome-languages.c
@@ -678,6 +678,19 @@ get_first_item_in_semicolon_list (const char *list)
}
static char *
+capitalize_utf8_string (const char *str)
+{
+ char first[8] = { 0 };
+
+ if (!str)
+ return NULL;
+
+ g_unichar_to_utf8 (g_unichar_totitle (g_utf8_get_char (str)), first);
+
+ return g_strconcat (first, g_utf8_offset_to_pointer (str, 1), NULL);
+}
+
+static char *
get_translated_language (const char *code,
const char *locale)
{
@@ -699,8 +712,10 @@ get_translated_language (const char *code,
if (is_fallback_language (code)) {
name = g_strdup (_("Unspecified"));
} else {
+ g_autofree char *tmp = NULL;
translated_name = dgettext ("iso_639", language);
- name = get_first_item_in_semicolon_list (translated_name);
+ tmp = get_first_item_in_semicolon_list (translated_name);
+ name = capitalize_utf8_string (tmp);
}
if (locale != NULL) {
@@ -742,6 +757,7 @@ get_translated_territory (const char *code,
if (territory != NULL) {
const char *translated_territory;
g_autofree char *old_locale = NULL;
+ g_autofree char *tmp = NULL;
if (locale != NULL) {
old_locale = g_strdup (setlocale (LC_MESSAGES, NULL));
@@ -749,7 +765,8 @@ get_translated_territory (const char *code,
}
translated_territory = dgettext ("iso_3166", territory);
- name = get_first_item_in_semicolon_list (translated_territory);
+ tmp = get_first_item_in_semicolon_list (translated_territory);
+ name = capitalize_utf8_string (tmp);
if (locale != NULL) {
setlocale (LC_MESSAGES, old_locale);