gdm r6138 - in trunk: . gui/simple-greeter



Author: halfline
Date: Wed Apr  9 04:52:37 2008
New Revision: 6138
URL: http://svn.gnome.org/viewvc/gdm?rev=6138&view=rev

Log:
2008-04-08 Ray Strode <rstrode redhat com>

	* gui/simple-greeter/gdm-languages.c:
	(language_name_has_translations),
	(add_locale), (collect_locales):
	When generating language list, use the list from libc
	as definitive, but prune from that list languages that
	lack translations in /usr/share/locale.  Previously
	we were trying to figure out the list of available languages
	from the names in /usr/share/locale, but those names aren't
	specific enough to get a name from.


Modified:
   trunk/ChangeLog
   trunk/gui/simple-greeter/gdm-languages.c

Modified: trunk/gui/simple-greeter/gdm-languages.c
==============================================================================
--- trunk/gui/simple-greeter/gdm-languages.c	(original)
+++ trunk/gui/simple-greeter/gdm-languages.c	Wed Apr  9 04:52:37 2008
@@ -285,6 +285,42 @@
 }
 
 static gboolean
+language_name_has_translations (const char *language_name)
+{
+        GDir        *dir;
+        char        *path;
+        const char  *name;
+        gboolean     has_translations;
+
+        path = g_build_filename (GNOMELOCALEDIR, language_name, "LC_MESSAGES", NULL);
+
+        has_translations = FALSE;
+        dir = g_dir_open (path, 0, NULL);
+        g_free (path);
+
+        if (dir == NULL) {
+                goto out;
+        }
+
+        do {
+                name = g_dir_read_name (dir);
+
+                if (name == NULL) {
+                        break;
+                }
+
+                if (g_str_has_suffix (name, ".mo")) {
+                        has_translations = TRUE;
+                        break;
+                }
+        } while (name != NULL);
+        g_dir_close (dir);
+
+out:
+        return has_translations;
+}
+
+static gboolean
 add_locale (const char *language_name)
 {
         GdmLocale *locale;
@@ -307,6 +343,7 @@
                 return FALSE;
         }
 
+
         locale = g_new0 (GdmLocale, 1);
         gdm_parse_language_name (name,
                                  &locale->language_code,
@@ -321,6 +358,12 @@
         locale->name = construct_language_name (locale->language_code, locale->territory_code,
                                                 locale->codeset, locale->modifier);
 
+        if (!language_name_has_translations (locale->name) &&
+            !language_name_has_translations (locale->language_code)) {
+                gdm_locale_free (locale);
+                return FALSE;
+        }
+
         old_locale = g_hash_table_lookup (gdm_available_locales_map, locale->id);
         if (old_locale != NULL) {
                 if (strlen (old_locale->name) > strlen (locale->name)) {
@@ -334,7 +377,6 @@
         return TRUE;
 }
 
-#ifdef GDM_GET_LOCALES_FROM_LIBC
 struct nameent
 {
         char    *name;
@@ -398,7 +440,6 @@
         g_mapped_file_free (mapped);
         return locales_collected;
 }
-#endif
 
 static int
 select_dirs (const struct dirent *dirent)
@@ -456,13 +497,15 @@
                 gdm_available_locales_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) gdm_locale_free);
         }
 
-#ifdef GDM_GET_LOCALES_FROM_LIBC
         if (collect_locales_from_archive ()) {
                 return;
-        }
-#endif
+        } else {
+                g_warning ("Could not read list of available locales from libc, "
+                           "guessing possible locales from available translations, "
+                           "but list may be incomplete!");
 
-        collect_locales_from_directory ();
+                collect_locales_from_directory ();
+        }
 }
 
 static gboolean



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