[gnome-initial-setup/85-gnome-intial-setup-segfaults-possibly-due-to-locale-related-problems: 6/6] language: handle missing default locales



commit b21ac5f47e927110c2acaa7d10056bd38e30af8f
Author: Will Thompson <will willthompson co uk>
Date:   Sun Nov 24 07:24:55 2019 +0000

    language: handle missing default locales
    
    cc_common_language_get_initial_languages() hardcodes a list of languages
    to show (as well as the user's own and other users on the system). It is
    possible that these locales will not be present on the system. Detect
    this case in insert_language() and short-circuit.
    
    It also adds all locales used by users on the system. If the installed
    locales has changed since those users picked those locales, iso-codes
    translations for those locales may not be present. Handle this case by
    showing the current-locale names for the language and country in the
    list.
    
    See https://gitlab.gnome.org/GNOME/gnome-initial-setup/issues/85.

 gnome-initial-setup/cc-common-language.c                 | 11 ++++++++++-
 gnome-initial-setup/pages/language/cc-language-chooser.c |  7 ++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/gnome-initial-setup/cc-common-language.c b/gnome-initial-setup/cc-common-language.c
index cc3e8fe..0aba41f 100644
--- a/gnome-initial-setup/cc-common-language.c
+++ b/gnome-initial-setup/cc-common-language.c
@@ -235,11 +235,20 @@ static void
 insert_language (GHashTable *ht,
                  const char *lang)
 {
+        locale_t locale;
         char *label_own_lang;
         char *label_current_lang;
         char *label_untranslated;
         char *key;
 
+        locale = newlocale (LC_MESSAGES_MASK, lang, (locale_t) 0);
+        if (locale == (locale_t) 0) {
+                g_debug ("%s: Failed to create locale %s", G_STRFUNC, lang);
+                return;
+        }
+        freelocale (locale);
+
+
         key = g_strdup (lang);
 
         label_own_lang = gnome_get_language_from_locale (key, key);
@@ -248,7 +257,7 @@ insert_language (GHashTable *ht,
 
         /* We don't have a translation for the label in
          * its own language? */
-        if (g_strcmp0 (label_own_lang, label_untranslated) == 0) {
+        if (label_own_lang == NULL || g_strcmp0 (label_own_lang, label_untranslated) == 0) {
                 if (g_strcmp0 (label_current_lang, label_untranslated) == 0)
                         g_hash_table_insert (ht, key, g_strdup (label_untranslated));
                 else
diff --git a/gnome-initial-setup/pages/language/cc-language-chooser.c 
b/gnome-initial-setup/pages/language/cc-language-chooser.c
index c4f4ed6..3722de1 100644
--- a/gnome-initial-setup/pages/language/cc-language-chooser.c
+++ b/gnome-initial-setup/pages/language/cc-language-chooser.c
@@ -130,9 +130,14 @@ language_widget_new (const char *locale_id,
                 return NULL;
 
         language_name = gnome_get_language_from_code (language, locale_id);
+        if (language_name == NULL)
+                language_name = gnome_get_language_from_code (language, NULL);
 
-        if (country)
+        if (country) {
                 country_name = gnome_get_country_from_code (country, locale_id);
+                if (country_name == NULL)
+                        country_name = gnome_get_country_from_code (country, NULL);
+        }
 
         locale_name = gnome_get_language_from_locale (locale_id, locale_id);
         locale_current_name = gnome_get_language_from_locale (locale_id, NULL);


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