[libgweather] Stop using one XML file per language



commit a046fc7be69226d768712ecb91f5662bc9288c1d
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sun Jul 21 17:45:55 2013 +0200

    Stop using one XML file per language
    
    The XML files are huge and take hours to build. Also, once they're
    built we lose the information on the untranslated name.
    Instead, use one XML file with the C locale names and regular
    gettext to translate.
    There is a bit of build system plumbing involved, because we want
    to keep using a separate domain and po/ subdirectory (so that no
    translations are lost)

 Makefile.am                     |   18 +++++-
 autogen.sh                      |   56 +++++++++++++----
 configure.ac                    |   34 +---------
 data/Makefile.am                |   67 +++-----------------
 libgweather/gweather-location.c |   38 ++++--------
 libgweather/gweather-timezone.c |   14 +++--
 libgweather/parser.c            |  131 +++++++--------------------------------
 libgweather/parser.h            |   12 ++--
 libgweather/weather-priv.h      |    1 +
 libgweather/weather.c           |   14 +++-
 po-locations/LINGUAS            |   86 +++++++++++++++++++++++++
 po-locations/Makefile.am        |   11 ---
 12 files changed, 219 insertions(+), 263 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 4db073c..e6508c8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -32,5 +32,21 @@ dist-hook:
          echo A git checkout is required to generate ChangeLog >&2; \
        fi
 
-GITIGNOREFILES = $(PACKAGE)-\*.tar.{gz,bz2,xz}
+GITIGNOREFILES = \
+       $(PACKAGE)-\*.tar.{gz,bz2,xz} \
+       po-locations/Makefile.in.in \
+       po-locations/Makefile.in \
+       po-locations/Makefile \
+       po-locations/Makevars.template \
+       po-locations/POTFILES \
+       po-locations/Rules-quot \
+       po-locations/stamp-it \
+       po-locations/.intltool-merge-cache \
+       "po-locations/*.gmo" \
+       "po-locations/*.header" \
+       "po-locations/*.mo" \
+       "po-locations/*.sed" \
+       "po-locations/*.sin" \
+       po-locations/libgweather-locations.pot
+
 -include $(top_srcdir)/git.mk
diff --git a/autogen.sh b/autogen.sh
index c32b920..a21e354 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,23 +1,55 @@
 #!/bin/sh
 # Run this to generate all the initial makefiles, etc.
 
-srcdir=`dirname $0`
-test -z "$srcdir" && srcdir=.
-
 PKG_NAME="libgweather"
-REQUIRED_AUTOMAKE_VERSION=1.9
-REQUIRED_M4MACROS=introspection.m4
 
-(test -f $srcdir/configure.ac \
-  && test -f $srcdir/$PKG_NAME.doap) || {
+test -n "$srcdir" || srcdir=`dirname "$0"`
+test -n "$srcdir" || srcdir=.
+
+olddir=`pwd`
+cd "$srcdir"
+
+(test -f configure.ac \
+  && test -f $PKG_NAME.doap) || {
     echo -n "**Error**: Directory "\`$srcdir\'" does not look like the"
     echo " top-level $PKG_NAME directory"
     exit 1
 }
 
-which gnome-autogen.sh || {
-    echo "You need to install gnome-common."
-    exit 1
-}
+mkdir m4/
+
+GTKDOCIZE=$(which gtkdocize 2>/dev/null)
+if test -z $GTKDOCIZE; then
+        echo "You don't have gtk-doc installed, and thus won't be able to generate the documentation."
+        rm -f gtk-doc.make
+        cat > gtk-doc.make <<EOF
+EXTRA_DIST =
+CLEANFILES =
+EOF
+else
+        gtkdocize || exit $?
+fi
+
+AUTORECONF=`which autoreconf`
+if test -z $AUTORECONF; then
+        echo "*** No autoreconf found, please install it ***"
+        exit 1
+fi
+
+# README and INSTALL are required by automake, but may be deleted by clean
+# up rules. to get automake to work, simply touch these here, they will be
+# regenerated from their corresponding *.in files by ./configure anyway.
+touch README INSTALL
+
+autoreconf --force --install --verbose || exit $?
+intltoolize --force --automake || exit $?
+
+# Replace autopoint Makefile.in.in with intltool's one
+sed -e 's/subdir = po/subdir = po-locations/' \
+    -e 's/GETTEXT_PACKAGE = @GETTEXT_PACKAGE@/GETTEXT_PACKAGE = libgweather-locations/' \
+    po/Makefile.in.in > po-locations/Makefile.in.in
+
+# Now configure, if asked
+cd "$olddir"
+test -n "$NOCONFIGURE" || "$srcdir/configure" "$@"
 
-. gnome-autogen.sh
diff --git a/configure.ac b/configure.ac
index 6554475..4cd4793 100644
--- a/configure.ac
+++ b/configure.ac
@@ -39,25 +39,6 @@ AM_PROG_CC_C_O
 
 GLIB_GSETTINGS
 
-AC_ARG_ENABLE(all-translations-in-one-xml,
-        [AS_HELP_STRING([--enable-all-translations-in-one-xml],
-                        [Put all translations in a big Locations.xml file (slow to parse)])],
-        [enable_big_xml=yes],
-        [enable_big_xml=no])
-AM_CONDITIONAL(USE_ONE_BIG_XML, test "x$enable_big_xml" = "xyes")
-
-AC_ARG_ENABLE(locations-compression,
-        [AS_HELP_STRING([--enable-locations-compression],
-                        [Compress Locations.xml files])],
-        [enable_locations_compression=yes],
-        [enable_locations_compression=no])
-if test "x$enable_locations_compression" = "xyes"; then
-    COMPRESS_EXT=.gz
-else
-    COMPRESS_EXT=
-fi
-AC_SUBST(COMPRESS_EXT)
-
 GNOME_COMPILE_WARNINGS([maximum])
 
 dnl -- Check for GTK+ 3.0 (required) ------------------------------------------
@@ -77,11 +58,12 @@ dnl -- check for glib; redundant at this point, but sets $GLIB_MKENUMS
 AM_PATH_GLIB_2_0($GLIB_REQUIRED)
 
 dnl gettext
-IT_PROG_INTLTOOL([0.50.0])
-
 AM_GNU_GETTEXT_VERSION([0.18])
 AM_GNU_GETTEXT([external])
 
+IT_PROG_INTLTOOL([0.50.0])
+IT_PO_SUBDIR([po-locations])
+
 GETTEXT_PACKAGE=libgweather-3.0
 AC_SUBST(GETTEXT_PACKAGE)
 AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [Gettext Package])
@@ -205,7 +187,7 @@ AC_CONFIG_FILES([
 Makefile
 doc/Makefile
 po/Makefile.in
-po-locations/Makefile
+po-locations/Makefile.in
 libgweather/Makefile
 libgweather/gweather-3.0.pc
 libgweather/gweather-3.0-uninstalled.pc
@@ -216,12 +198,6 @@ schemas/Makefile
 ])
 AC_OUTPUT
 
-if test "x$enable_big_xml" = "xyes"; then
-       LOCATIONS_XML_TRANSLATIONS="one big file"
-else
-       LOCATIONS_XML_TRANSLATIONS="one file per translation"
-fi
-
 dnl ***************************************************************************
 dnl *** Display Summary                                                     ***
 dnl ***************************************************************************
@@ -232,6 +208,4 @@ libgweather-$VERSION configure summary:
        Source code location:           ${srcdir}
        Compiler:                       ${CC}
        Introspection support:          ${found_introspection}
-       Locations.xml translations:     ${LOCATIONS_XML_TRANSLATIONS}
-       Locations.xml compression:      ${enable_locations_compression}
 " >&2
diff --git a/data/Makefile.am b/data/Makefile.am
index e1441d3..3fbc252 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -9,77 +9,28 @@ libgweatherdtddir = $(pkgdatadir)
 libgweatherdtd_DATA = locations.dtd
 
 libgweatherlocationsdir = $(pkgdatadir)
-libgweatherlocations_in_files = Locations.xml.in
+libgweatherlocations_DATA = Locations.xml
 
-if USE_ONE_BIG_XML
-
-LOCATIONS_STAMP = 
-
-libgweatherlocations_DATA = $(libgweatherlocations_in_files:.xml.in=.xml$(COMPRESS_EXT))
-
-%.xml$(COMPRESS_EXT): %.xml.in $(wildcard $(top_srcdir)/po-locations/*.po)
-       $(AM_V_GEN)LC_ALL=C $(INTLTOOL_MERGE) -x -u -c $(top_builddir)/po-locations/.intltool-merge-cache 
$(top_srcdir)/po-locations $< `echo $@ | sed "s/.xml$(COMPRESS_EXT)/.xml/"` && \
-       if test "x$(COMPRESS_EXT)" = "x.gz"; then                               \
-               gzip --force `echo $@ | sed "s/.xml$(COMPRESS_EXT)/.xml/"`;     \
-       fi
-
-else # USE_ONE_BIG_XML
-
-LOCATIONS_STAMP = stamp-Locations.xml
-
-PO_LOCATIONS = $(shell if test -n "$(LINGUAS)"; then for lang in $(LINGUAS); do if test -f 
"$(top_srcdir)/po-locations/$$lang.po"; then echo "$(top_srcdir)/po-locations/$$lang.po "; fi; done; else for 
pofile in $(top_srcdir)/po-locations/*.po; do echo $$pofile; done; fi)
-
-# Helper variable
-libgweatherlocations_data = $(libgweatherlocations_in_files:.xml.in=.xml)
-
-libgweatherlocations_DATA = $(shell echo $(PO_LOCATIONS) | sed 
"s|$(top_srcdir)/po-locations/|Locations.|g;s|\.po|.xml$(COMPRESS_EXT)|g") 
$(libgweatherlocations_data)$(COMPRESS_EXT)
-
-# We need this step so that we merge all the make Locations.xy.xml destinations
-# into one unique destination. This makes -j2 work. (Else, we end up with
-# multiple and conflicting calls to intltool-merge)
-$(libgweatherlocations_DATA): $(LOCATIONS_STAMP)
-
-$(LOCATIONS_STAMP): $(libgweatherlocations_in_files) $(PO_LOCATIONS) Makefile
-       $(AM_V_at)LC_ALL=C $(INTLTOOL_MERGE) --multiple-output --xml-style --utf8 
--cache=$(top_builddir)/po-locations/.intltool-merge-cache $(top_srcdir)/po-locations $< 
$(libgweatherlocations_data) && \
-       for pofile in $(PO_LOCATIONS); do \
-               locale=`echo $$pofile | sed "s;$(top_srcdir)/po-locations/\(.*\)\.po;\1;"`;     \
-               xmllint --noblanks -o Locations.$$locale.xml $$locale/$(libgweatherlocations_data); \
-               rm -f $$locale/$(libgweatherlocations_data);            \
-               test -d $$locale && rmdir $$locale;                     \
-               if test "x$(COMPRESS_EXT)" = "x.gz"; then               \
-                       gzip --force Locations.$$locale.xml;            \
-               fi;                                                     \
-       done &&                                                         \
-       xmllint --noblanks -o Locations.xml C/$(libgweatherlocations_data) && \
-       rm -f C/$(libgweatherlocations_data) &&                         \
-       test -d C && rmdir C &&                                         \
-       if test "x$(COMPRESS_EXT)" = "x.gz"; then                       \
-               gzip --force Locations.xml;                             \
-       fi &&                                                           \
-       touch $@
-
-endif # USE_ONE_BIG_XML
-
-### Locations.xml.in rebuild
+### Locations.xml rebuild
 rebuild-locations: locationdb.sqlite update-locations.py
-       $(AM_V_GEN)($(srcdir)/update-locations.py > Locations.xml.in.new && mv Locations.xml.in.new 
Locations.xml.in) || rm -f Locations.xml.in.new
+       $(AM_V_GEN)($(srcdir)/update-locations.py > Locations.xml.new && mv Locations.xml.new Locations.xml) 
|| rm -f Locations.xml.new
 
 locationdb.sqlite: build-locationdb.pl major-cities.txt sources/nsd_cccc.txt sources/POP_PLACES.txt 
sources/US_CONCISE.txt sources/geonames_dd_dms_date_*.txt city-fixups.pl station-fixups.pl
        $(AM_V_GEN)$(srcdir)/build-locationdb.pl
 
 check:
-       xmllint --valid --noout $(top_srcdir)/data/Locations.xml.in
-       $(srcdir)/check-timezones.sh $(srcdir)/Locations.xml.in
+       xmllint --valid --noout $(top_srcdir)/data/Locations.xml
+       $(srcdir)/check-timezones.sh $(srcdir)/Locations.xml
+
+ INTLTOOL_XML_NOMERGE_RULE@
 
 EXTRA_DIST =   \
-       $(libgweatherlocations_in_files)        \
+       Locations.xml.in                        \
        $(libgweatherdtd_DATA)                  \
        check-timezones.sh                      \
        README                                  \
        README.timezones
 
-CLEANFILES =   \
-       $(libgweatherlocations_DATA)            \
-       $(LOCATIONS_STAMP)
+CLEANFILES = $(libgweatherlocations_DATA)
 
 -include $(top_srcdir)/git.mk
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index acf54c8..89010cb 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -154,54 +154,53 @@ location_new_from_xml (GWeatherParser *parser, GWeatherLocationLevel level,
 
        tagname = (const char *) xmlTextReaderConstName (parser->xml);
        if (!strcmp (tagname, "name") && !loc->name) {
-           value = gweather_parser_get_localized_value (parser);
+           value = _gweather_parser_get_localized_value (parser);
            if (!value)
                goto error_out;
-           loc->name = g_strdup (value);
-           xmlFree (value);
+           loc->name = value;
            normalized = g_utf8_normalize (loc->name, -1, G_NORMALIZE_ALL);
            loc->sort_name = g_utf8_casefold (normalized, -1);
            g_free (normalized);
 
        } else if (!strcmp (tagname, "iso-code") && !loc->country_code) {
-           value = gweather_parser_get_value (parser);
+           value = _gweather_parser_get_value (parser);
            if (!value)
                goto error_out;
            loc->country_code = g_strdup (value);
            xmlFree (value);
        } else if (!strcmp (tagname, "tz-hint") && !loc->tz_hint) {
-           value = gweather_parser_get_value (parser);
+           value = _gweather_parser_get_value (parser);
            if (!value)
                goto error_out;
            loc->tz_hint = g_strdup (value);
            xmlFree (value);
        } else if (!strcmp (tagname, "code") && !loc->station_code) {
-           value = gweather_parser_get_value (parser);
+           value = _gweather_parser_get_value (parser);
            if (!value)
                goto error_out;
            loc->station_code = g_strdup (value);
            xmlFree (value);
        } else if (!strcmp (tagname, "coordinates") && !loc->latlon_valid) {
-           value = gweather_parser_get_value (parser);
+           value = _gweather_parser_get_value (parser);
            if (!value)
                goto error_out;
            if (parse_coordinates (value, &loc->latitude, &loc->longitude))
                loc->latlon_valid = TRUE;
            xmlFree (value);
        } else if (!strcmp (tagname, "zone") && !loc->forecast_zone) {
-           value = gweather_parser_get_value (parser);
+           value = _gweather_parser_get_value (parser);
            if (!value)
                goto error_out;
            loc->forecast_zone = g_strdup (value);
            xmlFree (value);
        } else if (!strcmp (tagname, "yahoo-woeid") && !loc->yahoo_id) {
-           value = gweather_parser_get_value (parser);
+           value = _gweather_parser_get_value (parser);
            if (!value)
                goto error_out;
            loc->yahoo_id = g_strdup (value);
            xmlFree (value);
        } else if (!strcmp (tagname, "radar") && !loc->radar) {
-           value = gweather_parser_get_value (parser);
+           value = _gweather_parser_get_value (parser);
            if (!value)
                goto error_out;
            loc->radar = g_strdup (value);
@@ -211,19 +210,7 @@ location_new_from_xml (GWeatherParser *parser, GWeatherLocationLevel level,
            child = location_new_from_xml (parser, GWEATHER_LOCATION_REGION, loc);
            if (!child)
                goto error_out;
-           if (parser->use_regions)
-               g_ptr_array_add (children, child);
-           else {
-               if (child->children) {
-                   for (i = 0; child->children[i]; i++) {
-                       /* Correct back pointers */
-                       child->children[i]->parent = loc;
-                       g_ptr_array_add (children, child->children[i]);
-                   }
-               }
-               child->children = NULL;
-               gweather_location_unref (child);
-           }
+           g_ptr_array_add (children, child);
        } else if (!strcmp (tagname, "country")) {
            child = location_new_from_xml (parser, GWEATHER_LOCATION_COUNTRY, loc);
            if (!child)
@@ -251,7 +238,7 @@ location_new_from_xml (GWeatherParser *parser, GWeatherLocationLevel level,
            g_ptr_array_add (children, child);
 
        } else if (!strcmp (tagname, "timezones")) {
-           loc->zones = gweather_timezones_parse_xml (parser);
+           loc->zones = _gweather_timezones_parse_xml (parser);
            if (!loc->zones)
                goto error_out;
 
@@ -314,11 +301,12 @@ gweather_location_get_world (void)
     GWeatherParser *parser;
 
     if (!global_world) {
-       parser = gweather_parser_new (TRUE);
+       parser = _gweather_parser_new ();
        if (!parser)
            return NULL;
 
        global_world = location_new_from_xml (parser, GWEATHER_LOCATION_WORLD, NULL);
+       _gweather_parser_free (parser);
     }
 
     return global_world;
diff --git a/libgweather/gweather-timezone.c b/libgweather/gweather-timezone.c
index 6b7f5dd..cb09009 100644
--- a/libgweather/gweather-timezone.c
+++ b/libgweather/gweather-timezone.c
@@ -154,7 +154,8 @@ static GWeatherTimezone *
 parse_timezone (GWeatherParser *parser)
 {
     GWeatherTimezone *zone = NULL;
-    char *id = NULL, *name = NULL;
+    char *id = NULL;
+    char *name = NULL;
     int offset = 0, dst_offset = 0;
     gboolean has_dst = FALSE;
 
@@ -178,7 +179,7 @@ parse_timezone (GWeatherParser *parser)
            }
 
            if (!strcmp ((const char *) xmlTextReaderConstName (parser->xml), "name"))
-               name = gweather_parser_get_localized_value (parser);
+               name = _gweather_parser_get_localized_value (parser);
            else {
                if (xmlTextReaderNext (parser->xml) != 1)
                    break;
@@ -191,21 +192,22 @@ parse_timezone (GWeatherParser *parser)
        zone = g_slice_new0 (GWeatherTimezone);
        zone->ref_count = 1;
        zone->id = g_strdup (id);
-       zone->name = g_strdup (name);
+       zone->name = name;
        zone->offset = offset;
        zone->has_dst = has_dst;
        zone->dst_offset = dst_offset;
+
+       name = NULL;
     }
 
+    g_free (name);
     xmlFree (id);
-    if (name)
-       xmlFree (name);
 
     return zone;
 }
 
 GWeatherTimezone **
-gweather_timezones_parse_xml (GWeatherParser *parser)
+_gweather_timezones_parse_xml (GWeatherParser *parser)
 {
     GPtrArray *zones;
     GWeatherTimezone *zone;
diff --git a/libgweather/parser.c b/libgweather/parser.c
index 837444b..4ff01ef 100644
--- a/libgweather/parser.c
+++ b/libgweather/parser.c
@@ -31,8 +31,8 @@
 #include <glib.h>
 #include <libxml/xmlreader.h>
 
-/**
- * gweather_parser_get_value:
+/*
+ * _gweather_parser_get_value:
  * @parser: a #GWeatherParser
  *
  * Gets the text of the element whose start tag @parser is pointing to.
@@ -42,7 +42,7 @@
  * string, or %NULL if the node is empty.
  **/
 char *
-gweather_parser_get_value (GWeatherParser *parser)
+_gweather_parser_get_value (GWeatherParser *parser)
 {
     char *value;
 
@@ -73,84 +73,28 @@ gweather_parser_get_value (GWeatherParser *parser)
     return value;
 }
 
-/**
- * gweather_parser_get_localized_value:
+/*
+ * _gweather_parser_get_localized_value:
  * @parser: a #GWeatherParser
  *
  * Looks at the name of the element @parser is currently pointing to, and
- * returns the content of either that node, or a following node with
- * the same name but an "xml:lang" attribute naming one of the locale
- * languages. Leaves @parser pointing to the next node after the last
- * consecutive element with the same name as the original element.
+ * returns the content of either that node, or the translation for
+ * it from the gettext domain for gweather locations.
  *
  * Return value: the localized (or unlocalized) text, as a
- * libxml-allocated string, or %NULL if the node is empty.
+ * glib-allocated string, or %NULL if the node is empty.
  **/
 char *
-gweather_parser_get_localized_value (GWeatherParser *parser)
+_gweather_parser_get_localized_value (GWeatherParser *parser)
 {
-    const char *this_language;
-    int best_match = INT_MAX;
-    const char *lang, *tagname, *next_tagname;
-    gboolean keep_going;
-    char *name = NULL;
-    int i;
+    char *untranslated_value = _gweather_parser_get_value (parser);
+    char *ret;
 
-    tagname = (const char *) xmlTextReaderConstName (parser->xml);
+    ret = (char*) dgettext ("libgweather-locations", (char*) untranslated_value);
 
-    do {
-       /* First let's get the language */
-       lang = (const char *) xmlTextReaderConstXmlLang (parser->xml);
-
-       if (lang == NULL)
-           this_language = "C";
-       else
-           this_language = lang;
-
-       /* the next "node" is text node containing the actual name */
-       if (xmlTextReaderRead (parser->xml) != 1) {
-           if (name)
-               xmlFree (name);
-           return NULL;
-       }
-
-       for (i = 0; parser->locales[i] && i < best_match; i++) {
-           if (!strcmp (parser->locales[i], this_language)) {
-               /* if we've already encounted a less accurate
-                  translation, then free it */
-               g_free (name);
-
-               name = (char *) xmlTextReaderValue (parser->xml);
-               best_match = i;
-
-               break;
-           }
-       }
-
-       /* Skip to close tag */
-       while (xmlTextReaderNodeType (parser->xml) != XML_READER_TYPE_END_ELEMENT) {
-           if (xmlTextReaderRead (parser->xml) != 1) {
-               xmlFree (name);
-               return NULL;
-           }
-       }
-
-       /* Skip junk */
-       do {
-           if (xmlTextReaderRead (parser->xml) != 1) {
-               xmlFree (name);
-               return NULL;
-           }
-       } while (xmlTextReaderNodeType (parser->xml) != XML_READER_TYPE_ELEMENT &&
-                xmlTextReaderNodeType (parser->xml) != XML_READER_TYPE_END_ELEMENT);
-
-       /* if the next tag has the same name then keep going */
-       next_tagname = (const char *) xmlTextReaderConstName (parser->xml);
-       keep_going = !strcmp (next_tagname, tagname);
-
-    } while (keep_going);
-
-    return name;
+    ret = g_strdup (ret);
+    xmlFree (untranslated_value);
+    return ret;
 }
 
 static void
@@ -160,54 +104,23 @@ gweather_location_list_free (gpointer list)
 }
 
 GWeatherParser *
-gweather_parser_new (gboolean use_regions)
+_gweather_parser_new (void)
 {
     GWeatherParser *parser;
     int zlib_support;
-    int i, keep_going;
+    int keep_going;
     char *filename;
     char *tagname, *format;
     time_t now;
     struct tm tm;
 
+    _gweather_gettext_init ();
+
     parser = g_slice_new0 (GWeatherParser);
-    parser->use_regions = use_regions;
-    parser->locales = g_get_language_names ();
 
     zlib_support = xmlHasFeature (XML_WITH_ZLIB);
 
-    /* First try to load a locale-specific XML. It's much faster. */
-    filename = NULL;
-    for (i = 0; parser->locales[i] != NULL; i++) {
-       filename = g_strdup_printf ("%s/Locations.%s.xml",
-                                   GWEATHER_XML_LOCATION_DIR,
-                                   parser->locales[i]);
-
-       if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
-           break;
-
-       g_free (filename);
-       filename = NULL;
-
-        if (!zlib_support)
-            continue;
-
-       filename = g_strdup_printf ("%s/Locations.%s.xml.gz",
-                                   GWEATHER_XML_LOCATION_DIR,
-                                   parser->locales[i]);
-
-       if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
-           break;
-
-       g_free (filename);
-       filename = NULL;
-    }
-
-    /* Fall back on the file containing either all translations, or only
-     * the english names (depending on the configure flags).
-     */
-    if (!filename)
-       filename = g_build_filename (GWEATHER_XML_LOCATION_DIR, "Locations.xml", NULL);
+    filename = g_build_filename (GWEATHER_XML_LOCATION_DIR, "Locations.xml", NULL);
 
     if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR) && zlib_support) {
         g_free (filename);
@@ -258,12 +171,12 @@ gweather_parser_new (gboolean use_regions)
     return parser;
 
 error_out:
-    gweather_parser_free (parser);
+    _gweather_parser_free (parser);
     return NULL;
 }
 
 void
-gweather_parser_free (GWeatherParser *parser)
+_gweather_parser_free (GWeatherParser *parser)
 {
     if (parser->xml)
        xmlFreeTextReader (parser->xml);
diff --git a/libgweather/parser.h b/libgweather/parser.h
index 6b1c807..02a0922 100644
--- a/libgweather/parser.h
+++ b/libgweather/parser.h
@@ -26,19 +26,17 @@
 
 typedef struct {
     xmlTextReaderPtr xml;
-    const char * const *locales;
-    gboolean use_regions;
     time_t year_start, year_end;
     GHashTable *metar_code_cache;
 } GWeatherParser;
 
-GWeatherParser *gweather_parser_new                 (gboolean        use_regions);
-void            gweather_parser_free                (GWeatherParser *parser);
+GWeatherParser *_gweather_parser_new                 (void);
+void            _gweather_parser_free                (GWeatherParser *parser);
 
-char           *gweather_parser_get_value           (GWeatherParser *parser);
-char           *gweather_parser_get_localized_value (GWeatherParser *parser);
+char           *_gweather_parser_get_value           (GWeatherParser *parser);
+char           *_gweather_parser_get_localized_value (GWeatherParser *parser);
 
 /* from gweather-timezone.c */
-GWeatherTimezone **gweather_timezones_parse_xml (GWeatherParser *parser);
+GWeatherTimezone **_gweather_timezones_parse_xml (GWeatherParser *parser);
 
 #endif
diff --git a/libgweather/weather-priv.h b/libgweather/weather-priv.h
index bfa7912..aca3d7e 100644
--- a/libgweather/weather-priv.h
+++ b/libgweather/weather-priv.h
@@ -36,6 +36,7 @@
 
 const char *gweather_gettext (const char *str) G_GNUC_FORMAT (1);
 const char *gweather_dpgettext (const char *context, const char *str) G_GNUC_FORMAT (2);
+void        _gweather_gettext_init (void);
 #define _(str) (gweather_gettext (str))
 #define C_(context, str) (gweather_dpgettext (context, str))
 #define N_(str) (str)
diff --git a/libgweather/weather.c b/libgweather/weather.c
index 072045e..d8e6399 100644
--- a/libgweather/weather.c
+++ b/libgweather/weather.c
@@ -78,8 +78,8 @@ static guint gweather_info_signals[SIGNAL_LAST];
 
 G_DEFINE_TYPE (GWeatherInfo, gweather_info, G_TYPE_OBJECT);
 
-static inline void
-gweather_gettext_init (void)
+void
+_gweather_gettext_init (void)
 {
     static gsize gweather_gettext_initialized = FALSE;
 
@@ -88,6 +88,12 @@ gweather_gettext_init (void)
 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 #endif
+
+        bindtextdomain ("libgweather-locations", GNOMELOCALEDIR);
+#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
+        bind_textdomain_codeset ("libgweather-locations", "UTF-8");
+#endif
+
         g_once_init_leave (&gweather_gettext_initialized, TRUE);
     }
 }
@@ -95,7 +101,7 @@ gweather_gettext_init (void)
 const char *
 gweather_gettext (const char *str)
 {
-    gweather_gettext_init ();
+    _gweather_gettext_init ();
     return dgettext (GETTEXT_PACKAGE, str);
 }
 
@@ -103,7 +109,7 @@ const char *
 gweather_dpgettext (const char *context,
                     const char *str)
 {
-    gweather_gettext_init ();
+    _gweather_gettext_init ();
     return g_dpgettext2 (GETTEXT_PACKAGE, context, str);
 }
 
diff --git a/po-locations/LINGUAS b/po-locations/LINGUAS
new file mode 100644
index 0000000..0214348
--- /dev/null
+++ b/po-locations/LINGUAS
@@ -0,0 +1,86 @@
+ang
+ar
+as
+ast
+az
+be latin
+be
+bg
+bn_IN
+bn
+br
+bs
+ca
+ca valencia
+crh
+cs
+cy
+da
+de
+dz
+el
+en_CA
+en_GB
+en shaw
+eo
+es
+et
+eu
+fa
+fi
+fr
+ga
+gl
+gu
+he
+hi
+hr
+hu
+id
+it
+ja
+ka
+kn
+ko
+ku
+ky
+lt
+lv
+mai
+mg
+mk
+ml
+mn
+mr
+ms
+nb
+nds
+ne
+nl
+nn
+oc
+or
+pa
+pl
+pt_BR
+pt
+ro
+ru
+rw
+si
+sk
+sl
+sq
+sr latin
+sr
+sv
+ta
+te
+th
+tr
+ug
+uk
+vi
+zh_CN
+zh_HK
+zh_TW


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