Add internationalisation with intltool and gettext
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Feb 2018 14:04:25 +0000 (14:04 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Feb 2018 14:04:25 +0000 (14:04 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
autogen.sh
configure.ac
m4/.gitignore
po/.gitignore [new file with mode: 0644]
po/LINGUAS [new file with mode: 0644]
po/POTFILES.in [new file with mode: 0644]
src/python/location-query.in

index 161f5d3..fc6f313 100644 (file)
@@ -3,6 +3,8 @@ CLEANFILES =
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 AM_MAKEFLAGS = --no-print-directory
 
+SUBDIRS = . po
+
 AM_CPPFLAGS = \
        -include $(top_builddir)/config.h \
        -DSYSCONFDIR=\""$(sysconfdir)"\" \
@@ -36,6 +38,12 @@ pkgconfigdir = $(libdir)/pkgconfig
 %: %.in Makefile
        $(SED_PROCESS)
 
+@INTLTOOL_POLICY_RULE@
+
+.PHONY: update-po
+update-po:
+       $(MAKE) -C po update-po
+
 EXTRA_DIST += \
        examples/python/create-database.py \
        examples/python/read-database.py
index 16c0eb3..ba2845a 100755 (executable)
@@ -8,6 +8,7 @@ if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then
         echo "Activated pre-commit hook."
 fi
 
+intltoolize --force --automake
 autoreconf --install --symlink
 
 libdir() {
index 3bd88a2..567c611 100644 (file)
@@ -29,6 +29,10 @@ LT_INIT([
 ])
 AC_PREFIX_DEFAULT([/usr])
 
+IT_PROG_INTLTOOL([0.40.0])
+GETTEXT_PACKAGE=${PACKAGE_TARNAME}
+AC_SUBST(GETTEXT_PACKAGE)
+
 AC_PROG_SED
 AC_PROG_MKDIR_P
 
@@ -82,6 +86,7 @@ PKG_CHECK_MODULES([PYTHON], [python-${PYTHON_VERSION}])
 AC_CONFIG_HEADERS(config.h)
 AC_CONFIG_FILES([
         Makefile
+        po/Makefile.in
 ])
 
 AC_OUTPUT
index 38066dd..55eaa80 100644 (file)
@@ -1,3 +1,4 @@
+intltool.m4
 libtool.m4
 ltoptions.m4
 ltsugar.m4
diff --git a/po/.gitignore b/po/.gitignore
new file mode 100644 (file)
index 0000000..bf46c1e
--- /dev/null
@@ -0,0 +1,6 @@
+/POTFILES
+/Makefile.in.in
+/.intltool-merge-cache
+/Makefile
+/stamp-it
+*.pot
diff --git a/po/LINGUAS b/po/LINGUAS
new file mode 100644 (file)
index 0000000..323d4df
--- /dev/null
@@ -0,0 +1 @@
+# nothing, yet
diff --git a/po/POTFILES.in b/po/POTFILES.in
new file mode 100644 (file)
index 0000000..9d7af9f
--- /dev/null
@@ -0,0 +1 @@
+src/python/location-query.in
index e750ea4..b5c1008 100644 (file)
@@ -18,6 +18,7 @@
 ###############################################################################
 
 import argparse
+import gettext
 import sys
 import syslog
 
@@ -25,7 +26,11 @@ import syslog
 import location
 
 # i18n
-_ = lambda x: x
+def _(singular, plural=None, n=None):
+       if plural:
+               return gettext.dngettext("libloc", singular, plural, n)
+
+       return gettext.dgettext("libloc", singular)
 
 class CLI(object):
        def __init__(self):