[Libosinfo] [RFC PATCH 5/5] osinfo_loader: do not use xpath to read localized strings

Giuseppe Scrivano gscrivan at redhat.com
Tue Jun 3 14:08:12 UTC 2014


Signed-off-by: Giuseppe Scrivano <gscrivan at redhat.com>
---
 osinfo/osinfo_loader.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 2a7d748..bcd1b1d 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -297,32 +297,24 @@ static void osinfo_loader_entity(OsinfoLoader *loader,
                                  GError **err)
 {
     int i = 0;
-    const gchar * const *langs = g_get_language_names ();
 
     /* Standard well-known keys first, allow single value only */
     for (i = 0 ; keys != NULL && keys[i].name != NULL; i++) {
         gchar *value_str = NULL;
         gboolean value_bool = FALSE;
         gchar *xpath = NULL;
-        int j;
         xmlXPathCompExprPtr comp;
 
         /* We are guaranteed to have at least the default "C" locale and we
          * want to ignore that, hence the NULL check on index 'j + 1'.
          */
         if (keys[i].type == G_TYPE_STRING) {
-            for (j = 0; langs[j + 1] != NULL; j++) {
-                xpath = g_strdup_printf("string(./%s[lang('%s')])",
-                                        keys[i].name, langs[j]);
-                comp = osinfo_loader_get_comp_xpath(loader, xpath);
-                value_str = osinfo_loader_string(comp, ctxt, err);
-                g_free(xpath);
-                xpath = NULL;
-                if (error_is_set(err))
-                    return;
-
-                if (value_str != NULL)
+            xmlNodePtr it;
+            for (it = root->children; it; it = it->next) {
+                if (xmlStrEqual(it->name, BAD_CAST keys[i].name)) {
+                    value_str = g_strdup(gettext((const char *) it->children->content));
                     break;
+                }
             }
         }
 
-- 
1.9.3




More information about the Libosinfo mailing list