From: Michael Tremer Date: Thu, 1 Feb 2018 14:04:25 +0000 (+0000) Subject: Add internationalisation with intltool and gettext X-Git-Tag: 0.9.0~74 X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Flibloc.git;a=commitdiff_plain;h=2bb7d64e8803d64f525c2408cb25825473a8a001 Add internationalisation with intltool and gettext Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 161f5d3..fc6f313 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/autogen.sh b/autogen.sh index 16c0eb3..ba2845a 100755 --- a/autogen.sh +++ b/autogen.sh @@ -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() { diff --git a/configure.ac b/configure.ac index 3bd88a2..567c611 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/m4/.gitignore b/m4/.gitignore index 38066dd..55eaa80 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -1,3 +1,4 @@ +intltool.m4 libtool.m4 ltoptions.m4 ltsugar.m4 diff --git a/po/.gitignore b/po/.gitignore new file mode 100644 index 0000000..bf46c1e --- /dev/null +++ b/po/.gitignore @@ -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 index 0000000..323d4df --- /dev/null +++ b/po/LINGUAS @@ -0,0 +1 @@ +# nothing, yet diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 0000000..9d7af9f --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1 @@ +src/python/location-query.in diff --git a/src/python/location-query.in b/src/python/location-query.in index e750ea4..b5c1008 100644 --- a/src/python/location-query.in +++ b/src/python/location-query.in @@ -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):