libgweather r161 - in trunk: . data libgweather



Author: vuntz
Date: Thu Apr 10 19:31:26 2008
New Revision: 161
URL: http://svn.gnome.org/viewvc/libgweather?rev=161&view=rev

Log:
2008-04-10  Vincent Untz  <vuntz gnome org>

	Create a Locations.xml file per translation. This makes the parsing
	of the XML file much much faster (down to ~0.25s from ~1.5s for me).
	Also remove the spaces from the XML files (down from ~0.3s to ~0.25s).
	There is a configure flag to keep the old behavior:
	--enable-all-translations-in-one-xml

	* configure.in: add --enable-all-translations-in-one-xml configure flag
	* data/Makefile.am: pretty much rewrite to handle the new feature.
	Note that we don't distribute locations_diff.py anymore. It's mainly
	useful when hacking.
	* libgweather/Makefile.am: small update
	* libgweather/gweather-xml.c: (gweather_xml_load_locations): look for
	localized xml files first, and then fallback on Locations.xml


Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/data/   (props changed)
   trunk/data/Makefile.am
   trunk/libgweather/Makefile.am
   trunk/libgweather/gweather-xml.c

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Thu Apr 10 19:31:26 2008
@@ -33,6 +33,13 @@
 AM_PROG_LIBTOOL
 AC_PATH_PROG(GCONFTOOL, gconftool-2)
 
+AC_ARG_ENABLE(all-translations-in-one-xml,
+        [AC_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")
+
 GNOME_COMPILE_WARNINGS
 
 dnl ***************************************************************************
@@ -154,6 +161,12 @@
 data/Makefile
 ])
 
+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 ***************************************************************************
@@ -163,4 +176,5 @@
 	Prefix:				${prefix}
 	Source code location:		${srcdir}
 	Compiler:			${CC}
+	Locations.xml translations:	${LOCATIONS_XML_TRANSLATIONS}
 " >&2

Modified: trunk/data/Makefile.am
==============================================================================
--- trunk/data/Makefile.am	(original)
+++ trunk/data/Makefile.am	Thu Apr 10 19:31:26 2008
@@ -1,17 +1,47 @@
-EXTRA_DIST =			\
-	check-timezones.sh	\
-	locations_diff.py	\
-	locations.dtd		\
-	Locations.xml           \
-	Locations.xml.in	\
-	README
+libgweatherdtddir = $(pkgdatadir)
+libgweatherdtd_DATA = locations.dtd
 
 libgweatherlocationsdir = $(pkgdatadir)
 libgweatherlocations_in_files = Locations.xml.in
-dist_libgweatherlocations_DATA = $(libgweatherlocations_in_files:.xml.in=.xml) locations.dtd
+
+if USE_ONE_BIG_XML
+
+libgweatherlocations_DATA = $(libgweatherlocations_in_files:.xml.in=.xml)
+
 %.xml: %.xml.in $(wildcard $(top_srcdir)/po-locations/*.po)
 	LC_ALL=C $(INTLTOOL_MERGE) -x -u -c $(top_builddir)/po-locations/.intltool-merge-cache $(top_srcdir)/po-locations $< $@
 
+else # USE_ONE_BIG_XML
+
+PO_LOCATIONS = $(wildcard $(top_srcdir)/po-locations/*.po)
+
+# 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|g") $(libgweatherlocations_data)
+
+$(libgweatherlocations_DATA): $(libgweatherlocations_in_files) $(PO_LOCATIONS)
+	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;			\
+	done
+	xmllint --noblanks -o Locations.xml C/$(libgweatherlocations_data)
+	rm -f C/$(libgweatherlocations_data)
+	test -d C && rmdir C
+
+endif # USE_ONE_BIG_XML
+
 check:
-	xmllint --valid --noout $(srcdir)/Locations.xml.in && \
+	xmllint --valid --noout $(top_srcdir)/data/Locations.xml.in
 	$(srcdir)/check-timezones.sh $(srcdir)/Locations.xml.in
+
+EXTRA_DIST =	\
+	$(libgweatherlocations_in_files)	\
+	check-timezones.sh			\
+	README
+
+CLEANFILES =	\
+	$(libgweatherlocations_DATA)

Modified: trunk/libgweather/Makefile.am
==============================================================================
--- trunk/libgweather/Makefile.am	(original)
+++ trunk/libgweather/Makefile.am	Thu Apr 10 19:31:26 2008
@@ -24,7 +24,7 @@
 	$(GNOME_VFS_APPLETS_CFLAGS)	\
 	-DG_LOG_DOMAIN=\"GWeather\"	\
 	-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
-	-DGWEATHER_XML_LOCATION=\""$(pkgdatadir)/Locations.xml"\"
+	-DGWEATHER_XML_LOCATION_DIR=\""$(pkgdatadir)"\"
 
 libgweather_la_LIBADD = \
 	$(GTK_LIBS)	\

Modified: trunk/libgweather/gweather-xml.c
==============================================================================
--- trunk/libgweather/gweather-xml.c	(original)
+++ trunk/libgweather/gweather-xml.c	Thu Apr 10 19:31:26 2008
@@ -369,14 +369,42 @@
 GtkTreeModel *
 gweather_xml_load_locations( void )
 {
+  const char * const *languages;
+  int i;
+  char *filename;
   char *tagname, *format;
   GtkTreeSortable *sortable;
   GtkTreeStore *store = NULL;
   xmlTextReaderPtr xml;
   int keep_going;
 
+  /* First try to load a locale-specific XML. It's much faster. */
+  languages = g_get_language_names ();
+  filename = NULL;
+
+  for (i = 0; languages[i] != NULL; i++)
+    {
+      filename = g_strdup_printf ("%s/Locations.%s.xml",
+                                  GWEATHER_XML_LOCATION_DIR, languages[i]);
+
+      if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
+        break;
+
+      g_free (filename);
+      filename = NULL;
+    }
+
+  /* Fallback on the file containing either all translations, or only
+   * the english names (depending on the configure flags). Note that it's
+   * also the file that is advertised in our pkg-config file, so it's
+   * part of the API. */
+  if (!filename)
+    filename = g_strdup (GWEATHER_XML_LOCATION_DIR"/Locations.xml");
+
   /* Open the xml file containing the different locations */
-  xml = xmlNewTextReaderFilename (GWEATHER_XML_LOCATION);
+  xml = xmlNewTextReaderFilename (filename);
+  g_free (filename);
+
   if( xml == NULL )
     return NULL;
 



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