$OpenBSD: patch-libgnome-desktop_gnome-languages_c,v 1.3 2013/08/28 09:45:12 ajacoutot Exp $

https://bugzilla.gnome.org/show_bug.cgi?id=698383

--- libgnome-desktop/gnome-languages.c.orig	Sun Mar 17 02:49:53 2013
+++ libgnome-desktop/gnome-languages.c	Wed Aug 28 10:48:56 2013
@@ -310,11 +310,7 @@ language_name_is_valid (const char *language_name)
 {
         char     *old_locale;
         gboolean  is_valid;
-#ifdef WITH_INCOMPLETE_LOCALES
         int lc_type_id = LC_CTYPE;
-#else
-        int lc_type_id = LC_MESSAGES;
-#endif
 
         old_locale = g_strdup (setlocale (lc_type_id, NULL));
         is_valid = setlocale (lc_type_id, language_name) != NULL;
@@ -445,22 +441,11 @@ add_locale (const char *language_name,
         g_free (name);
         name = NULL;
 
-#ifdef WITH_INCOMPLETE_LOCALES
-        if (utf8_only) {
-                if (locale->territory_code == NULL || locale->modifier) {
-                        g_debug ("Ignoring '%s' as a locale, since it lacks territory code or modifier", name);
-                        gnome_locale_free (locale);
-                        return FALSE;
-                }
-        }
-#endif
-
         locale->id = construct_language_name (locale->language_code, locale->territory_code,
                                               NULL, locale->modifier);
         locale->name = construct_language_name (locale->language_code, locale->territory_code,
                                                 locale->codeset, locale->modifier);
 
-#ifndef WITH_INCOMPLETE_LOCALES
         if (!gnome_language_has_translations (locale->name) &&
             !gnome_language_has_translations (locale->id) &&
             !gnome_language_has_translations (locale->language_code) &&
@@ -469,7 +454,6 @@ add_locale (const char *language_name,
                 gnome_locale_free (locale);
                 return FALSE;
         }
-#endif
 
         if (!utf8_only) {
                 g_free (locale->id);
@@ -631,6 +615,40 @@ collect_locales_from_directory (void)
         return found_locales;
 }
 
+static gboolean
+collect_locales_from_localebin (void)
+{
+        gboolean found_locales = FALSE;
+        FILE *p;
+        char *buf, *lbuf;
+        size_t len;
+
+        p = popen("locale -a", "r");
+
+        lbuf = NULL;
+        while ((buf = fgetln(p, &len))) {
+                if (buf[len - 1] == '\n') {
+                        buf[len - 1] = '\0';
+                        if (add_locale (buf, TRUE))
+                                found_locales = TRUE;
+                } else {
+                        /* EOF without EOL, copy and add the NUL */
+                        lbuf = malloc(len + 1);
+                        if (lbuf == NULL)
+                                break;
+                        memcpy(lbuf, buf, len);
+                        lbuf[len] = '\0';
+                        if (add_locale (lbuf, TRUE))
+                                found_locales = TRUE;
+                        free(lbuf);
+                }
+        }
+
+        pclose(p);
+
+        return found_locales;
+}
+
 static void
 count_languages_and_territories (void)
 {
@@ -669,6 +687,7 @@ collect_locales (void)
 {
         gboolean found_archive_locales = FALSE;
         gboolean found_dir_locales = FALSE;
+        gboolean found_localebin_locales = FALSE;
         GError *error = NULL;
 
         if (gnome_available_locales_map == NULL) {
@@ -683,12 +702,12 @@ collect_locales (void)
 
         found_dir_locales = collect_locales_from_directory ();
 
-        if (!(found_archive_locales || found_dir_locales)) {
-#ifndef WITH_INCOMPLETE_LOCALES
+        found_localebin_locales = collect_locales_from_localebin ();
+
+        if (!(found_archive_locales || found_dir_locales || found_localebin_locales)) {
                 g_warning ("Could not read list of available locales from libc, "
                            "guessing possible locales from available translations, "
                            "but list may be incomplete!");
-#endif
         }
 
 	count_languages_and_territories ();
