[virt-tools-list] [libosinfo v6 1/4] Add translation framework
Zeeshan Ali (Khattak)
zeeshanak at gnome.org
Mon Oct 29 14:43: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).
---
.gitignore | 15 +++++++++++++++
Makefile.am | 28 +++++++++++++++++++++++++++-
autogen.sh | 1 +
configure.ac | 10 ++++++++++
osinfo/Makefile.am | 1 +
osinfo/osinfo_loader.c | 4 ++++
tools/Makefile.am | 1 +
tools/osinfo-db-validate.c | 7 +++++++
tools/osinfo-detect.c | 7 +++++++
tools/osinfo-install-script.c | 7 +++++++
tools/osinfo-query.c | 7 +++++++
11 files changed, 87 insertions(+), 1 deletion(-)
create mode 100644 po/POTFILES.in
diff --git a/.gitignore b/.gitignore
index ab30e42..4383a35 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,9 @@ config.h.in
config.log
config.status
configure
+intltool-extract.in
+intltool-merge.in
+intltool-update.in
libtool
m4
stamp-h1
@@ -71,3 +74,15 @@ tools/osinfo-install-script
tools/osinfo-install-script.exe
tools/osinfo-install-script.1
docs/reference/Libosinfo.types
+po/Makefile.in.in
+po/POTFILES
+po/libosinfo.pot
+po/stamp-it
+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
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..8741756 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,6 +12,15 @@ 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_GNU_GETTEXT([external])
+AM_GNU_GETTEXT_VERSION([0.17])
+
# 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 +189,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..3642a61 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,9 @@ osinfo_loader_class_init (OsinfoLoaderClass *klass)
{
GObjectClass *g_klass = G_OBJECT_CLASS (klass);
+ bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+
g_klass->finalize = osinfo_loader_finalize;
g_type_class_add_private (klass, sizeof (OsinfoLoaderPrivate));
diff --git a/po/POTFILES.in b/po/POTFILES.in
new file mode 100644
index 0000000..e69de29
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 51e6df1..8494439 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -2,6 +2,7 @@ AM_CFLAGS = $(GOBJECT_CFLAGS) \
$(GIO_CFLAGS) \
$(LIBXML_CFLAGS) \
-DPKGDATADIR="\"$(pkgdatadir)\"" \
+ -DLOCALEDIR="\"$(datadir)/locale\"" \
$(WARN_CFLAGS) \
-I$(top_srcdir) \
$(NULL)
diff --git a/tools/osinfo-db-validate.c b/tools/osinfo-db-validate.c
index 65454d7..5b7274b 100644
--- a/tools/osinfo-db-validate.c
+++ b/tools/osinfo-db-validate.c
@@ -26,6 +26,8 @@
#include <glib.h>
#include <gio/gio.h>
#include <libxml/relaxng.h>
+#include <locale.h>
+#include <glib/gi18n.h>
#define SCHEMA PKGDATADIR "/schemas/libosinfo.rng"
@@ -248,6 +250,11 @@ gint main(gint argc, gchar **argv)
GError *error = NULL;
gint ret = EXIT_FAILURE;
+ setlocale(LC_ALL, "");
+ textdomain (GETTEXT_PACKAGE);
+ bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+
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..1b94e36 100644
--- a/tools/osinfo-detect.c
+++ b/tools/osinfo-detect.c
@@ -26,6 +26,8 @@
#include <osinfo/osinfo.h>
#include <string.h>
+#include <locale.h>
+#include <glib/gi18n.h>
#define FORMAT_STR_PLAIN "plain"
#define FORMAT_STR_ENV "env"
@@ -183,6 +185,11 @@ gint main(gint argc, gchar **argv)
OsinfoOs *os = NULL;
gint ret = 0;
+ setlocale(LC_ALL, "");
+ textdomain (GETTEXT_PACKAGE);
+ bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+
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..66116e1 100644
--- a/tools/osinfo-install-script.c
+++ b/tools/osinfo-install-script.c
@@ -25,6 +25,8 @@
#include <osinfo/osinfo.h>
#include <string.h>
+#include <locale.h>
+#include <glib/gi18n.h>
static const gchar *profile;
static const gchar *output_dir;
@@ -163,6 +165,11 @@ gint main(gint argc, gchar **argv)
OsinfoOs *os = NULL;
gint ret = 0;
+ setlocale(LC_ALL, "");
+ textdomain (GETTEXT_PACKAGE);
+ bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+
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..006f86d 100644
--- a/tools/osinfo-query.c
+++ b/tools/osinfo-query.c
@@ -28,6 +28,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <locale.h>
+#include <glib/gi18n.h>
#include <osinfo/osinfo.h>
@@ -359,6 +361,11 @@ gint main(gint argc, gchar **argv)
const gchar *sortKey = NULL;
const gchar *fields = NULL;
+ setlocale(LC_ALL, "");
+ textdomain (GETTEXT_PACKAGE);
+ bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+
g_type_init();
struct OsinfoType types[] = {
--
1.7.12.1
More information about the virt-tools-list
mailing list