>From 15bdf2a8ed6e3655775042fd8b3b83253c49718e Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Wed, 14 May 2008 14:04:35 +0100
Subject: [PATCH] Add i18n support

This will be needed to get better error messages to
users of the D-Bus API. We use glib's builtin gettext
support. No strings marked as translatable yet, we'll
need to mark those user-visible strings carefully and
review them.
---
 Makefile.am     |    2 +-
 autogen.sh      |    2 ++
 configure.ac    |    6 ++++++
 po/POTFILES.in  |    1 +
 src/Makefile.am |    2 +-
 src/main.c      |    7 +++++++
 6 files changed, 18 insertions(+), 2 deletions(-)
 create mode 100644 po/POTFILES.in

diff --git a/Makefile.am b/Makefile.am
index 18e45a7..62e9de8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
 AUTOMAKE_OPTIONS = dist-bzip2
-SUBDIRS = src data tests
+SUBDIRS = src data tests po
 EXTRA_DIST = TODO
 
diff --git a/autogen.sh b/autogen.sh
index 373ed82..096ac20 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 aclocal || exit 1
+autoheader || exit 1
+glib-gettextize -f -c || exit 1
 autoconf || exit 1
 automake -a -c || exit 1
 ./configure $*
diff --git a/configure.ac b/configure.ac
index 094deb7..37253c5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,11 +1,17 @@
 AC_INIT([fprintd], [0.1])
 AM_INIT_AUTOMAKE
 AC_CONFIG_SRCDIR([src/main.c])
+AC_CONFIG_HEADERS([config.h])
 
 AC_PREREQ([2.50])
 AC_PROG_CC
 AM_PROG_CC_C_O
 
+GETTEXT_PACKAGE=fprintd
+AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, ["$GETTEXT_PACKAGE"], [Define to the Gettext package name])
+AC_SUBST(GETTEXT_PACKAGE)
+AM_GLIB_GNU_GETTEXT
+
 PKG_CHECK_MODULES(FPRINT, [libfprint > 0.1.0])
 AC_SUBST(FPRINT_LIBS)
 AC_SUBST(FPRINT_CFLAGS)
diff --git a/po/POTFILES.in b/po/POTFILES.in
new file mode 100644
index 0000000..e723152
--- /dev/null
+++ b/po/POTFILES.in
@@ -0,0 +1 @@
+src/main.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 77e4fee..4c7afd5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,7 +8,7 @@ libexec_PROGRAMS = fprintd
 
 fprintd_SOURCES = main.c manager.c device.c file_storage.c
 fprintd_LDADD = $(GLIB_LIBS) $(DBUS_GLIB_LIBS) $(FPRINT_LIBS)
-fprintd_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS) $(FPRINT_CFLAGS)
+fprintd_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS) $(FPRINT_CFLAGS) -DLOCALEDIR=\""$(datadir)/locale"\"
 
 manager-dbus-glue.h: manager.xml
 	dbus-binding-tool --prefix=fprint_manager --mode=glib-server $< --output=$@
diff --git a/src/main.c b/src/main.c
index 5d25b66..b6ca1d2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -17,11 +17,14 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include "config.h"
+
 #include <poll.h>
 #include <stdlib.h>
 
 #include <dbus/dbus-glib-bindings.h>
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <libfprint/fprint.h>
 #include <glib-object.h>
 
@@ -205,6 +208,10 @@ int main(int argc, char **argv)
 	guint32 request_name_ret;
 	int r = 0;
 
+	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
 	r = fp_init();
 	if (r < 0) {
 		g_error("fprint init failed with error %d\n", r);
-- 
1.5.4.5

