148 lines
4.3 KiB
Diff
148 lines
4.3 KiB
Diff
From 49c4fdd0a30d07fe1ba73644aca44a4732c03e1f Mon Sep 17 00:00:00 2001
|
|
From: fujiwarat <takao.fujiwara1@gmail.com>
|
|
Date: Wed, 27 Feb 2019 19:45:06 +0900
|
|
Subject: [PATCH] src: Make ISO 639 language names with title
|
|
|
|
Danish translations are small in iso-codes-iso-639-2-da.po for the
|
|
genral usage but the users ask the title format on UI.
|
|
Now ibus_get_language_name() and ibus_get_untranslated_language_name()
|
|
return the dynamic allocation instead of the static characters
|
|
to make the capital character.
|
|
|
|
BUG=https://github.com/ibus/ibus/issues/2079
|
|
---
|
|
src/ibusutil.c | 63 ++++++++++++++++++++++++++++++++++++++++++--------
|
|
src/ibusutil.h | 8 +++----
|
|
2 files changed, 58 insertions(+), 13 deletions(-)
|
|
|
|
diff --git a/src/ibusutil.c b/src/ibusutil.c
|
|
index fd1da006..9d003e2e 100644
|
|
--- a/src/ibusutil.c
|
|
+++ b/src/ibusutil.c
|
|
@@ -2,7 +2,7 @@
|
|
/* vim:set et sts=4: */
|
|
/* bus - The Input Bus
|
|
* Copyright (C) 2008-2015 Peng Huang <shawn.p.huang@gmail.com>
|
|
- * Copyright (C) 2010-2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
|
|
+ * Copyright (C) 2010-2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
|
|
* Copyright (C) 2008-2016 Red Hat, Inc.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
@@ -125,8 +125,8 @@ _load_lang()
|
|
ibus_xml_free (node);
|
|
}
|
|
|
|
-const gchar *
|
|
-ibus_get_untranslated_language_name (const gchar *_locale)
|
|
+const static gchar *
|
|
+ibus_get_untranslated_raw_language_name (const gchar *_locale)
|
|
{
|
|
const gchar *retval;
|
|
gchar *p = NULL;
|
|
@@ -148,19 +148,64 @@ ibus_get_untranslated_language_name (const gchar *_locale)
|
|
return "Other";
|
|
}
|
|
|
|
-const gchar *
|
|
+static char *
|
|
+get_first_item_in_semicolon_list (const char *list)
|
|
+{
|
|
+ char **items;
|
|
+ char *item;
|
|
+
|
|
+ items = g_strsplit (list, "; ", 2);
|
|
+
|
|
+ item = g_strdup (items[0]);
|
|
+ g_strfreev (items);
|
|
+
|
|
+ return item;
|
|
+}
|
|
+
|
|
+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);
|
|
+}
|
|
+
|
|
+gchar *
|
|
+ibus_get_untranslated_language_name (const gchar *_locale)
|
|
+{
|
|
+ const gchar *raw = ibus_get_untranslated_raw_language_name (_locale);
|
|
+ gchar *tmp = get_first_item_in_semicolon_list (raw);
|
|
+ gchar *retval = capitalize_utf8_string (tmp);
|
|
+ g_free (tmp);
|
|
+ return retval;
|
|
+}
|
|
+
|
|
+gchar *
|
|
ibus_get_language_name (const gchar *_locale)
|
|
{
|
|
- const gchar *retval = ibus_get_untranslated_language_name (_locale);
|
|
+ const gchar *raw = ibus_get_untranslated_raw_language_name (_locale);
|
|
+ const gchar *translation = NULL;
|
|
+ gchar *tmp;
|
|
+ gchar *retval;
|
|
|
|
#ifdef ENABLE_NLS
|
|
- if (g_strcmp0 (retval, "Other") == 0)
|
|
- return dgettext (GETTEXT_PACKAGE, N_("Other"));
|
|
+ if (g_strcmp0 (raw, "Other") == 0)
|
|
+ return g_strdup (dgettext (GETTEXT_PACKAGE, N_("Other")));
|
|
else
|
|
- return dgettext ("iso_639-3", retval);
|
|
+ translation = dgettext ("iso_639-3", raw);
|
|
#else
|
|
- return retval;
|
|
+ translation = raw;
|
|
#endif
|
|
+
|
|
+ tmp = get_first_item_in_semicolon_list (translation);
|
|
+ retval = capitalize_utf8_string (tmp);
|
|
+ g_free (tmp);
|
|
+ return retval;
|
|
}
|
|
|
|
void
|
|
diff --git a/src/ibusutil.h b/src/ibusutil.h
|
|
index 226dd7a8..795365f6 100644
|
|
--- a/src/ibusutil.h
|
|
+++ b/src/ibusutil.h
|
|
@@ -2,8 +2,8 @@
|
|
/* vim:set et sts=4: */
|
|
/* bus - The Input Bus
|
|
* Copyright (C) 2008-2015 Peng Huang <shawn.p.huang@gmail.com>
|
|
- * Copyright (C) 2010-2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
|
|
- * Copyright (C) 2008-2016 Red Hat, Inc.
|
|
+ * Copyright (C) 2010-2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
|
|
+ * Copyright (C) 2008-2018 Red Hat, Inc.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
@@ -42,7 +42,7 @@
|
|
*
|
|
* Returns: untranslated language name
|
|
*/
|
|
-const gchar * ibus_get_untranslated_language_name
|
|
+gchar * ibus_get_untranslated_language_name
|
|
(const gchar *_locale);
|
|
|
|
/**
|
|
@@ -51,6 +51,6 @@ const gchar * ibus_get_untranslated_language_name
|
|
*
|
|
* Returns: translated language name
|
|
*/
|
|
-const gchar * ibus_get_language_name (const gchar *_locale);
|
|
+gchar * ibus_get_language_name (const gchar *_locale);
|
|
|
|
#endif
|
|
--
|
|
2.20.1
|
|
|