[gnome-desktop] gnome-languages: Capitalize language and territory names
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-desktop] gnome-languages: Capitalize language and territory names
- Date: Mon, 15 Feb 2016 16:58:54 +0000 (UTC)
commit 104fb3d9397d7834762cf3b49e01c3f80d69af49
Author: Rui Matos <tiagomatos gmail com>
Date: Tue Feb 9 18:11:58 2016 +0100
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
libgnome-desktop/gnome-languages.c | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/libgnome-desktop/gnome-languages.c b/libgnome-desktop/gnome-languages.c
index ec23a7a..cbf82d3 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]