diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2004-10-31 23:26:42 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2004-10-31 23:26:42 +0800 |
commit | 48cf478f03ec2e047c5d95a00a940c3b723a2ea2 (patch) | |
tree | 82189f4b4d1b04078f6bb59a594d749cfff393c2 /src | |
parent | 27cb305ae1978811ffe3734dc04b0a4b468ac9bc (diff) | |
download | gsoc2013-epiphany-48cf478f03ec2e047c5d95a00a940c3b723a2ea2.tar gsoc2013-epiphany-48cf478f03ec2e047c5d95a00a940c3b723a2ea2.tar.gz gsoc2013-epiphany-48cf478f03ec2e047c5d95a00a940c3b723a2ea2.tar.bz2 gsoc2013-epiphany-48cf478f03ec2e047c5d95a00a940c3b723a2ea2.tar.lz gsoc2013-epiphany-48cf478f03ec2e047c5d95a00a940c3b723a2ea2.tar.xz gsoc2013-epiphany-48cf478f03ec2e047c5d95a00a940c3b723a2ea2.tar.zst gsoc2013-epiphany-48cf478f03ec2e047c5d95a00a940c3b723a2ea2.zip |
Process xml:lang in extension description files.
2004-10-31 Christian Persch <chpe@cvs.gnome.org>
* src/ephy-extensions-manager.c: (assign_localised_string),
(ephy_extensions_manager_load_string),
(ephy_extensions_manager_class_init):
Process xml:lang in extension description files.
Diffstat (limited to 'src')
-rw-r--r-- | src/ephy-extensions-manager.c | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/src/ephy-extensions-manager.c b/src/ephy-extensions-manager.c index a940daca4..dda3f71d1 100644 --- a/src/ephy-extensions-manager.c +++ b/src/ephy-extensions-manager.c @@ -293,6 +293,43 @@ find_extension_info (const ExtensionInfo *info, return strcmp (info->info.identifier, identifier); } +typedef struct +{ + xmlChar *string; + guint match; +} LocalisedString; + +static const char * const *languages = NULL; + +static void +assign_localised_string (xmlTextReaderPtr reader, + LocalisedString *string) +{ + const xmlChar *value, *lang; + guint i; + + lang = xmlTextReaderConstXmlLang (reader); + value = xmlTextReaderConstValue (reader); + + if (G_UNLIKELY (lang == NULL)) + { + /* languages always has "C" in it, so make sure we get a match */ + lang = (const xmlChar *) "C"; + } + + for (i = 0; languages[i] != NULL && i < string->match; i++) + { + if (lang != NULL && + strcmp ((const char *) lang, languages[i]) == 0) + { + xmlFree (string->string); + string->string = xmlStrdup (value); + string->match = i; + break; + } + } +} + typedef enum { STATE_START, @@ -323,6 +360,8 @@ ephy_extensions_manager_load_string (EphyExtensionsManager *manager, EphyExtensionInfo *einfo; ExtensionInfo *info; int ret; + LocalisedString description = { NULL, G_MAXUINT }; + LocalisedString name = { NULL, G_MAXUINT }; LOG ("Loading description file for '%s'", identifier) @@ -347,6 +386,7 @@ ephy_extensions_manager_load_string (EphyExtensionsManager *manager, return; } + /* Validate the extension description */ if (manager->priv->schema_ctxt) { if (xmlSchemaValidateDoc (manager->priv->schema_ctxt, doc)) @@ -357,7 +397,8 @@ ephy_extensions_manager_load_string (EphyExtensionsManager *manager, return; } } - + + /* Now parse it */ reader = xmlReaderWalker (doc); g_return_if_fail (reader != NULL); @@ -472,8 +513,7 @@ ephy_extensions_manager_load_string (EphyExtensionsManager *manager, else if (state == STATE_DESCRIPTION && type == XML_READER_TYPE_TEXT) { - - einfo->description = xmlTextReaderValue (reader); + assign_localised_string (reader, &description); } else if (state == STATE_GETTEXT_DOMAIN && type == XML_READER_TYPE_TEXT) @@ -497,7 +537,7 @@ ephy_extensions_manager_load_string (EphyExtensionsManager *manager, else if (state == STATE_NAME && type == XML_READER_TYPE_TEXT) { - einfo->name = xmlTextReaderValue (reader); + assign_localised_string (reader, &name); } else if (state == STATE_VERSION && type == XML_READER_TYPE_TEXT) @@ -593,6 +633,10 @@ ephy_extensions_manager_load_string (EphyExtensionsManager *manager, xmlFreeTextReader (reader); xmlFreeDoc (doc); + /* assign localised strings */ + einfo->description = description.string; + einfo->name = name.string; + /* sanity check */ if (ret < 0 || state != STATE_STOP || einfo->name == NULL || einfo->description == NULL || @@ -1219,4 +1263,7 @@ ephy_extensions_manager_class_init (EphyExtensionsManagerClass *class) G_TYPE_POINTER); g_type_class_add_private (object_class, sizeof (EphyExtensionsManagerPrivate)); + + languages = g_get_language_names (); + g_assert (languages != NULL); } |