[gnome-software: 1/2] fedora-langpacks: Drop codeset and modifier from locale




commit e93a6fee4b1b1602e4d08e83e8805ec7c5865e8c
Author: Sundeep Anand <suanand redhat com>
Date:   Fri May 6 11:10:08 2022 +0000

    fedora-langpacks: Drop codeset and modifier from locale
    
    Previously a `UTF-8` suffix was removed from the locale strings by
    the caller. See 7a838ffbe817755726c10b8c03f266091caeca61.
    
    However, now the plugin receives locale string with codeset (`UTF-8`)
    information, which should be removed to match langpacks. The locale
    can also include a modifier (`@cyrillic`), which should also be removed.
    
    Due to this, langpacks for `zh_*`, `en_GB` and `pt_BR` were not getting
    installed. This change fixes the issue.
    
    Update fedora-langpacks test case for locale with codeset information.
    
    Signed-off-by: Sundeep Anand <suanand redhat com>
    
    Fixes: #1747

 plugins/fedora-langpacks/gs-plugin-fedora-langpacks.c | 12 ++++++++++++
 plugins/fedora-langpacks/gs-self-test.c               |  6 +++---
 2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/plugins/fedora-langpacks/gs-plugin-fedora-langpacks.c 
b/plugins/fedora-langpacks/gs-plugin-fedora-langpacks.c
index accbf5b35..cea7d6c06 100644
--- a/plugins/fedora-langpacks/gs-plugin-fedora-langpacks.c
+++ b/plugins/fedora-langpacks/gs-plugin-fedora-langpacks.c
@@ -70,11 +70,23 @@ gs_plugin_add_langpacks (GsPlugin *plugin,
                         GError **error)
 {
        GsPluginFedoraLangpacks *self = GS_PLUGIN_FEDORA_LANGPACKS (plugin);
+       gchar *separator;
        const gchar *language_code;
        g_autofree gchar *cachefn = NULL;
        g_autofree gchar *langpack_pkgname = NULL;
        g_auto(GStrv) language_region = NULL;
 
+       /* This plugin may receive user locale in the form as documented in `man 3 setlocale`:
+        *
+        * language[_territory][.codeset][@modifier]
+        *
+        * e.g. `ja_JP.UTF-8` or `en_GB.iso88591` or `uz_UZ.utf8@cyrillic` or `de_DE@euro`
+        * Get the locale without codeset and modifier as required for langpacks.
+        */
+       separator = strpbrk (locale, ".@");
+       if (separator != NULL)
+               *separator = '\0';
+
        if (g_strrstr (locale, "_") != NULL &&
            !g_hash_table_lookup (self->locale_langpack_map, locale)) {
                /*
diff --git a/plugins/fedora-langpacks/gs-self-test.c b/plugins/fedora-langpacks/gs-self-test.c
index 6a0d99dde..c56058aef 100644
--- a/plugins/fedora-langpacks/gs-self-test.c
+++ b/plugins/fedora-langpacks/gs-self-test.c
@@ -31,7 +31,7 @@ gs_plugins_fedora_langpacks_func (GsPluginLoader *plugin_loader)
        }
 
        /* start with a clean slate */
-       cachefn = gs_utils_get_cache_filename ("langpacks", "langpacks-ja",
+       cachefn = gs_utils_get_cache_filename ("langpacks", "langpacks-pt_BR",
                                               GS_UTILS_CACHE_FLAG_WRITEABLE |
                                               GS_UTILS_CACHE_FLAG_CREATE_DIRECTORY,
                                               &error);
@@ -40,7 +40,7 @@ gs_plugins_fedora_langpacks_func (GsPluginLoader *plugin_loader)
 
        /* get langpacks result based on locale */
        plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_LANGPACKS,
-                                        "search", "ja_JP",
+                                        "search", "pt_BR.UTF-8",
                                         "refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON,
                                         NULL);
        list = gs_plugin_loader_job_process (plugin_loader, plugin_job, NULL, &error);
@@ -52,7 +52,7 @@ gs_plugins_fedora_langpacks_func (GsPluginLoader *plugin_loader)
 
        /* check app's source and kind */
        app = gs_app_list_index (list, 0);
-       g_assert_cmpstr (gs_app_get_source_default (app), ==, "langpacks-ja");
+       g_assert_cmpstr (gs_app_get_source_default (app), ==, "langpacks-pt_BR");
        g_assert_cmpint (gs_app_get_kind (app), ==, AS_COMPONENT_KIND_LOCALIZATION);
 }
 


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