[gtk: 1/2] emoji: Try to load emoji data using both language and territory
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 1/2] emoji: Try to load emoji data using both language and territory
- Date: Sat, 8 May 2021 02:07:21 +0000 (UTC)
commit 0769dfbd32d00938e3051634dd29997d3ed94691
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Fri May 7 16:03:37 2021 +0200
emoji: Try to load emoji data using both language and territory
When loading the emoji data we just try to get the data for a language
while there may be territory specializations and emojibase provides
them.
So, split the loading function and try to load the data for the fully
defined language string (i.e. `it-ch`) before loading the generic one
for the language (i.e. `it`) and eventually falling back to the generic
english.
gtk/gtkemojichooser.c | 50 ++++++++++++++++++++++++++++++++++----------------
1 file changed, 34 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkemojichooser.c b/gtk/gtkemojichooser.c
index 97738b947c..86d6572c8f 100644
--- a/gtk/gtkemojichooser.c
+++ b/gtk/gtkemojichooser.c
@@ -595,25 +595,13 @@ add_emoji (GtkWidget *box,
gtk_flow_box_insert (GTK_FLOW_BOX (box), child, prepend ? 0 : -1);
}
-GBytes *
-get_emoji_data (void)
+static GBytes *
+get_emoji_data_by_language (const char *lang)
{
GBytes *bytes;
- const char *lang;
- char q[10];
char *path;
GError *error = NULL;
- lang = pango_language_to_string (gtk_get_default_language ());
- if (strchr (lang, '-'))
- {
- int i;
- for (i = 0; lang[i] != '-' && i < 9; i++)
- q[i] = lang[i];
- q[i] = '\0';
- lang = q;
- }
-
path = g_strconcat ("/org/gtk/libgtk/emoji/", lang, ".data", NULL);
bytes = g_resources_lookup_data (path, 0, &error);
if (bytes)
@@ -666,10 +654,40 @@ get_emoji_data (void)
}
g_clear_error (&error);
-
g_free (path);
- return g_resources_lookup_data ("/org/gtk/libgtk/emoji/en.data", 0, NULL);
+ return NULL;
+}
+
+GBytes *
+get_emoji_data (void)
+{
+ GBytes *bytes;
+ const char *lang;
+
+ lang = pango_language_to_string (gtk_get_default_language ());
+ bytes = get_emoji_data_by_language (lang);
+ if (bytes)
+ return bytes;
+
+ if (strchr (lang, '-'))
+ {
+ char q[5];
+ int i;
+
+ for (i = 0; lang[i] != '-' && i < 4; i++)
+ q[i] = lang[i];
+ q[i] = '\0';
+
+ bytes = get_emoji_data_by_language (q);
+ if (bytes)
+ return bytes;
+ }
+
+ bytes = get_emoji_data_by_language ("en");
+ g_assert (bytes);
+
+ return bytes;
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]