[gnome-software] gs-appstream: Fix comparison of languages from locales



commit 6cbdc1ebc8db64b623d907eeb55c9ffd157472ea
Author: Philip Withnall <withnall endlessm com>
Date:   Fri Oct 11 11:23:38 2019 +0100

    gs-appstream: Fix comparison of languages from locales
    
    We can’t just assume that the locale won’t have a codeset or modifier.
    Locales have the form: `language[_territory][.codeset][@modifier]`, and
    regularly do have all four components. See `locale -a` for an example.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 plugins/core/gs-appstream.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index 3ccaaf41..05c3d9f4 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -542,7 +542,7 @@ gs_appstream_refine_app_updates (GsPlugin *plugin,
 
 /**
  * _gs_utils_locale_has_translations:
- * @locale: A locale, e.g. "en_GB"
+ * @locale: A locale, e.g. `en_GB` or `uz_UZ.utf8@cyrillic`
  *
  * Looks up if the locale is likely to have translations.
  *
@@ -551,11 +551,19 @@ gs_appstream_refine_app_updates (GsPlugin *plugin,
 static gboolean
 _gs_utils_locale_has_translations (const gchar *locale)
 {
-       if (g_strcmp0 (locale, "C") == 0)
+       g_autofree gchar *locale_copy = g_strdup (locale);
+       gchar *separator;
+
+       /* Strip off the codeset and modifier, if present. */
+       separator = strpbrk (locale_copy, ".@");
+       if (separator != NULL)
+               *separator = '\0';
+
+       if (g_strcmp0 (locale_copy, "C") == 0)
                return FALSE;
-       if (g_strcmp0 (locale, "en") == 0)
+       if (g_strcmp0 (locale_copy, "en") == 0)
                return FALSE;
-       if (g_strcmp0 (locale, "en_US") == 0)
+       if (g_strcmp0 (locale_copy, "en_US") == 0)
                return FALSE;
        return TRUE;
 }


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