[tracker/collation-gconf-locale: 27/31] tracker-miner-applications: Use tracker-locale during key file extraction



commit ed0bb3e7caea286b401ed768eef979b5a9e8027f
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Tue Nov 16 17:09:36 2010 +0100

    tracker-miner-applications: Use tracker-locale during key file extraction

 src/miners/fs/tracker-miner-applications-meego.cpp |    2 +-
 src/miners/fs/tracker-miner-applications.c         |   59 +++++++++++++------
 2 files changed, 41 insertions(+), 20 deletions(-)
---
diff --git a/src/miners/fs/tracker-miner-applications-meego.cpp b/src/miners/fs/tracker-miner-applications-meego.cpp
index c4c777f..03cf5f4 100644
--- a/src/miners/fs/tracker-miner-applications-meego.cpp
+++ b/src/miners/fs/tracker-miner-applications-meego.cpp
@@ -30,7 +30,7 @@
  * localized strings using catalog and string ids. QApplication and
  * MLocale are needed for loading the translation catalogs. The
  * returned string is a multi-string one which has parts of different
- * lenght separated by '\x9C' unicode escape sequences.
+ * length separated by '\x9C' unicode escape sequences.
  *
  * FIXME: This is insane, try to get rid of at least some of the extra
  * layers here.
diff --git a/src/miners/fs/tracker-miner-applications.c b/src/miners/fs/tracker-miner-applications.c
index 26f49c1..a93b375 100644
--- a/src/miners/fs/tracker-miner-applications.c
+++ b/src/miners/fs/tracker-miner-applications.c
@@ -21,6 +21,7 @@
 
 #include <libtracker-common/tracker-utils.h>
 #include <libtracker-common/tracker-ontologies.h>
+#include <libtracker-common/tracker-locale.h>
 
 #include "tracker-miner-applications.h"
 
@@ -127,12 +128,18 @@ insert_data_from_desktop_file (TrackerSparqlBuilder *sparql,
                                const gchar          *metadata_key,
                                GKeyFile             *desktop_file,
                                const gchar          *key,
-                               gboolean              use_locale)
+                               const gchar          *locale)
 {
 	gchar *str;
 
-	if (use_locale) {
-		str = g_key_file_get_locale_string (desktop_file, GROUP_DESKTOP_ENTRY, key, NULL, NULL);
+	if (locale) {
+		/* Try to get the key with our desired LANG locale... */
+		str = g_key_file_get_locale_string (desktop_file, GROUP_DESKTOP_ENTRY, key, locale, NULL);
+		/* If our desired locale failed, use the list of LANG locales prepared by GLib
+		 * (will return untranslated string if none of the locales available) */
+		if (!str) {
+			str = g_key_file_get_locale_string (desktop_file, GROUP_DESKTOP_ENTRY, key, NULL, NULL);
+		}
 	} else {
 		str = g_key_file_get_string (desktop_file, GROUP_DESKTOP_ENTRY, key, NULL);
 	}
@@ -290,6 +297,7 @@ process_desktop_file (ProcessApplicationData  *data,
 	gsize cats_len;
 	gboolean is_software = TRUE;
 	const gchar *parent_urn;
+	gchar *lang;
 #ifdef HAVE_MEEGOTOUCH
 	gchar *logical_id = NULL;
 	gchar *translation_catalog = NULL;
@@ -301,11 +309,16 @@ process_desktop_file (ProcessApplicationData  *data,
 
 	path = g_file_get_path (data->file);
 
-	/* Try to get the categories with locale, then without if that fails */
-	cats = g_key_file_get_locale_string_list (key_file, GROUP_DESKTOP_ENTRY, "Categories", NULL, &cats_len, NULL);
+	/* Retrieve LANG locale setup */
+	lang = tracker_locale_get (TRACKER_LOCALE_LANGUAGE);
 
-	if (!cats)
-		cats = g_key_file_get_string_list (key_file, GROUP_DESKTOP_ENTRY, "Categories", &cats_len, NULL);
+	/* Try to get the categories with our desired LANG locale... */
+	cats = g_key_file_get_locale_string_list (key_file, GROUP_DESKTOP_ENTRY, "Categories", lang, &cats_len, NULL);
+	if (!cats) {
+		/* If our desired locale failed, use the list of LANG locales prepared by GLib
+		 * (will return untranslated string if none of the locales available) */
+		cats = g_key_file_get_locale_string_list (key_file, GROUP_DESKTOP_ENTRY, "Categories", NULL, &cats_len, NULL);
+	}
 
 	/* NOTE: We sanitize categories later on when iterating them */
 
@@ -323,12 +336,13 @@ process_desktop_file (ProcessApplicationData  *data,
 #endif /* HAVE_MEEGOTOUCH */
 
 	if (!name) {
-		/* Try to get the name with locale, then without if that fails */
-		name = g_key_file_get_locale_string (key_file, GROUP_DESKTOP_ENTRY, "Name", NULL, NULL);
-	}
-
-	if (!name) {
-		name = g_key_file_get_string (key_file, GROUP_DESKTOP_ENTRY, "Name", NULL);
+		/* Try to get the name with our desired LANG locale... */
+		name = g_key_file_get_locale_string (key_file, GROUP_DESKTOP_ENTRY, "Name", lang, NULL);
+		if (!name) {
+			/* If our desired locale failed, use the list of LANG locales prepared by GLib
+			 * (will return untranslated string if none of the locales available) */
+			name = g_key_file_get_locale_string (key_file, GROUP_DESKTOP_ENTRY, "Name", NULL, NULL);
+		}
 	}
 
 	/* Sanitize name */
@@ -505,12 +519,18 @@ process_desktop_file (ProcessApplicationData  *data,
 		if (is_software) {
 			gchar *icon;
 
-			insert_data_from_desktop_file (sparql, uri,
-			                               TRACKER_NIE_PREFIX "comment", key_file,
-			                               "Comment", TRUE);
-			insert_data_from_desktop_file (sparql, uri,
-			                               TRACKER_NFO_PREFIX "softwareCmdLine", key_file,
-			                               "Exec", TRUE);
+			insert_data_from_desktop_file (sparql,
+			                               uri,
+			                               TRACKER_NIE_PREFIX "comment",
+			                               key_file,
+			                               "Comment",
+			                               lang);
+			insert_data_from_desktop_file (sparql,
+			                               uri,
+			                               TRACKER_NFO_PREFIX "softwareCmdLine",
+			                               key_file,
+			                               "Exec",
+			                               lang);
 
 			icon = g_key_file_get_string (key_file, GROUP_DESKTOP_ENTRY, "Icon", NULL);
 
@@ -614,6 +634,7 @@ process_desktop_file (ProcessApplicationData  *data,
 	g_free (uri);
 	g_free (path);
 	g_free (name);
+	g_free (lang);
 }
 
 static void



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