[virt-tools-list] [libosinfo v2 1/4] Add translation framework

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Tue Oct 23 01:54:52 UTC 2012


From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>

Note that we are calling bindtextdomain() from Loader's class init.
AFAICT, its a common practice in libraries without any main _init()
function to make this call in init of the most common/useful class (e.g
gdk-pixbuf and gdbus).
---
 Makefile.am                   | 28 +++++++++++++++++++++++++++-
 autogen.sh                    |  1 +
 configure.ac                  |  9 +++++++++
 osinfo/Makefile.am            |  1 +
 osinfo/osinfo_loader.c        |  3 +++
 po/LINGUAS                    |  1 +
 tools/osinfo-db-validate.c    |  2 ++
 tools/osinfo-detect.c         |  3 +++
 tools/osinfo-install-script.c |  2 ++
 tools/osinfo-query.c          |  2 ++
 10 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 po/LINGUAS
 create mode 100644 po/POTFILES.in
 create mode 100644 po/POTFILES.skip

diff --git a/Makefile.am b/Makefile.am
index d605152..3d27bae 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,18 @@
 
-SUBDIRS = osinfo test data tools docs examples
+SUBDIRS = osinfo test data tools docs po examples
+
+INTLTOOL_FILES = \
+	intltool-extract.in \
+	intltool-merge.in \
+	intltool-update.in \
+	$(NULL)
+
+DISTCLEANFILES =				\
+	intltool-extract			\
+	intltool-merge				\
+	intltool-update				\
+	po/.intltool-merge-cache		\
+	$(NULL)
 
 EXTRA_DIST = \
   COPYING.LIB \
@@ -10,8 +23,21 @@ EXTRA_DIST = \
   cfg.mk \
   GNUmakefile \
   maint.mk \
+  $(INTLTOOL_FILES) \
   $(NULL)
 
+MAINTAINERCLEANFILES =				\
+	po/Makefile.in.in			\
+	po/Makevars.template			\
+	po/Rules-quot				\
+	po/boldquot.sed				\
+	po/en at boldquot.header			\
+	po/en at quot.header			\
+	po/insert-header.sin			\
+	po/quot.sed				\
+	po/remove-potcdate.sin			\
+	$(NULL)
+
 DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc
 
 ACLOCAL_AMFLAGS = -I m4
diff --git a/autogen.sh b/autogen.sh
index b5997e6..3255713 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -18,3 +18,4 @@ which gnome-autogen.sh || {
 }
 
 ACLOCAL_FLAGS="$ACLOCAL_FLAGS" USE_GNOME2_MACROS=1 . gnome-autogen.sh --enable-gtk-doc "$@"
+intltoolize -f
diff --git a/configure.ac b/configure.ac
index f021fb6..97f295c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,6 +12,14 @@ LIBOSINFO_COMPILE_WARNINGS
 GNOME_MAINTAINER_MODE_DEFINES
 AM_MAINTAINER_MODE([enable])
 
+# i18 support
+IT_PROG_INTLTOOL(0.40.0)
+
+GETTEXT_PACKAGE=AC_PACKAGE_NAME
+AC_SUBST(GETTEXT_PACKAGE)
+AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE],["$GETTEXT_PACKAGE"],[The name of the gettext domain])
+AM_GLIB_GNU_GETTEXT
+
 # Autoconf 2.61a.99 and earlier don't support linking a file only
 # in VPATH builds.  But since GNUmakefile is for maintainer use
 # only, it does not matter if we skip the link with older autoconf.
@@ -180,5 +188,6 @@ AC_CONFIG_FILES([
 	docs/Makefile
 	docs/reference/Makefile
 	examples/Makefile
+	po/Makefile.in
 ])
 AC_OUTPUT
diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
index 495d2f5..6ddb956 100644
--- a/osinfo/Makefile.am
+++ b/osinfo/Makefile.am
@@ -31,6 +31,7 @@ libosinfo_1_0_la_CFLAGS = \
 	$(GIO_CFLAGS) \
 	-DPKG_DATA_DIR='"$(pkgdatadir)"' \
 	-DSYS_CONF_DIR='"$(sysconfdir)"' \
+	-DLOCALEDIR="\"$(datadir)/locale\"" \
 	$(NULL)
 
 libosinfo_1_0_la_LDFLAGS = \
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 934c758..47db85b 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -23,6 +23,7 @@
  */
 
 #include <config.h>
+#include <glib/gi18n-lib.h>
 
 #include <osinfo/osinfo.h>
 
@@ -70,6 +71,8 @@ osinfo_loader_class_init (OsinfoLoaderClass *klass)
 {
     GObjectClass *g_klass = G_OBJECT_CLASS (klass);
 
+    bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
+
     g_klass->finalize = osinfo_loader_finalize;
 
     g_type_class_add_private (klass, sizeof (OsinfoLoaderPrivate));
diff --git a/po/LINGUAS b/po/LINGUAS
new file mode 100644
index 0000000..af407ee
--- /dev/null
+++ b/po/LINGUAS
@@ -0,0 +1 @@
+# Keep this list sorted alphabetically
diff --git a/po/POTFILES.in b/po/POTFILES.in
new file mode 100644
index 0000000..e69de29
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
new file mode 100644
index 0000000..e69de29
diff --git a/tools/osinfo-db-validate.c b/tools/osinfo-db-validate.c
index 65454d7..31bfeea 100644
--- a/tools/osinfo-db-validate.c
+++ b/tools/osinfo-db-validate.c
@@ -26,6 +26,7 @@
 #include <glib.h>
 #include <gio/gio.h>
 #include <libxml/relaxng.h>
+#include <locale.h>
 
 #define SCHEMA PKGDATADIR "/schemas/libosinfo.rng"
 
@@ -248,6 +249,7 @@ gint main(gint argc, gchar **argv)
     GError *error = NULL;
     gint ret = EXIT_FAILURE;
 
+    setlocale(LC_ALL, "");
     g_type_init();
 
     context = g_option_context_new("- Validate XML documents ");
diff --git a/tools/osinfo-detect.c b/tools/osinfo-detect.c
index c21ec5c..1186ca5 100644
--- a/tools/osinfo-detect.c
+++ b/tools/osinfo-detect.c
@@ -26,6 +26,7 @@
 
 #include <osinfo/osinfo.h>
 #include <string.h>
+#include <locale.h>
 
 #define FORMAT_STR_PLAIN "plain"
 #define FORMAT_STR_ENV "env"
@@ -183,6 +184,8 @@ gint main(gint argc, gchar **argv)
     OsinfoOs *os = NULL;
     gint ret = 0;
 
+    setlocale(LC_ALL, "");
+
     context = g_option_context_new("- Detect if media is bootable " \
                                    "and the relavent OS and distribution.");
     /* FIXME: We don't have a gettext package to pass to this function. */
diff --git a/tools/osinfo-install-script.c b/tools/osinfo-install-script.c
index 52acee2..53bcdef 100644
--- a/tools/osinfo-install-script.c
+++ b/tools/osinfo-install-script.c
@@ -25,6 +25,7 @@
 
 #include <osinfo/osinfo.h>
 #include <string.h>
+#include <locale.h>
 
 static const gchar *profile;
 static const gchar *output_dir;
@@ -163,6 +164,7 @@ gint main(gint argc, gchar **argv)
     OsinfoOs *os = NULL;
     gint ret = 0;
 
+    setlocale(LC_ALL, "");
     g_type_init();
 
     config = osinfo_install_config_new("http://libosinfo.fedorahosted.org/config");
diff --git a/tools/osinfo-query.c b/tools/osinfo-query.c
index 69b789a..f3ecd77 100644
--- a/tools/osinfo-query.c
+++ b/tools/osinfo-query.c
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include <locale.h>
 
 #include <osinfo/osinfo.h>
 
@@ -359,6 +360,7 @@ gint main(gint argc, gchar **argv)
     const gchar *sortKey = NULL;
     const gchar *fields = NULL;
 
+    setlocale(LC_ALL, "");
     g_type_init();
 
     struct OsinfoType types[] = {
-- 
1.7.12.1




More information about the virt-tools-list mailing list