[gnome-software] gs-appstream: Fix handling of language kudo for non-trivial locales



commit c62c78758ebdd7f674bbddf662726c78a0e8766d
Author: Philip Withnall <withnall endlessm com>
Date:   Fri Oct 11 11:24:56 2019 +0100

    gs-appstream: Fix handling of language kudo for non-trivial locales
    
    We can use the g_get_locale_variants() function from GLib to produce all
    the combinations of language, territory, codeset and modifier from the
    currently-set locale. This simplifies the code a little. Previously, the
    code would fail to correctly get the language if the user’s locale had a
    language and modifier, but no territory. (I don’t have any locales like
    that on my system, but it’s possible.)
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 plugins/core/gs-appstream.c | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)
---
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index 05c3d9f4..5b4dc5cf 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -568,20 +568,6 @@ _gs_utils_locale_has_translations (const gchar *locale)
        return TRUE;
 }
 
-static gchar *
-_gs_utils_get_language_from_locale (const gchar *locale)
-{
-       gchar *separator;
-
-       separator = strpbrk (locale, "._");
-
-       if (separator == NULL)
-               return NULL;
-
-       return g_strndup (locale, separator - locale);
-}
-
-
 static gboolean
 gs_appstream_origin_valid (const gchar *origin)
 {
@@ -953,14 +939,11 @@ gs_appstream_refine_app (GsPlugin *plugin,
                } else {
 
                        g_autoptr(GString) xpath = g_string_new (NULL);
-                       g_autofree gchar *language = NULL;
-
-                       xb_string_append_union (xpath, "languages/lang[text()='%s'][@percentage>50]", tmp);
+                       g_auto(GStrv) variants = g_get_locale_variants (tmp);
 
-                       language = _gs_utils_get_language_from_locale (tmp);
-                       if (language != NULL) {
-                               xb_string_append_union (xpath, "languages/lang[text()='%s'][@percentage>50]", 
language);
-                       }
+                       /* @variants includes @tmp */
+                       for (gsize i = 0; variants[i] != NULL; i++)
+                               xb_string_append_union (xpath, "languages/lang[text()='%s'][@percentage>50]", 
variants[i]);
 
                        if (xb_node_query_text (component, xpath->str, NULL) != NULL)
                                gs_app_add_kudo (app, GS_APP_KUDO_MY_LANGUAGE);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]