]> git.draconx.ca Git - dxcommon.git/commitdiff
Import gettext m4/automake bits from cdecl99.
authorNick Bowler <nbowler@draconx.ca>
Sat, 28 Jul 2012 19:16:42 +0000 (15:16 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sat, 28 Jul 2012 19:16:42 +0000 (15:16 -0400)
These are pretty package-agnostic, and can be shared pretty easily.

m4/linguas.m4 [new file with mode: 0644]
snippet/gettext.mk [new file with mode: 0644]

diff --git a/m4/linguas.m4 b/m4/linguas.m4
new file mode 100644 (file)
index 0000000..2ae8a9d
--- /dev/null
@@ -0,0 +1,53 @@
+dnl Copyright © 2011 Nick Bowler
+dnl
+dnl Computes the set of .po and .mo files based on the LINGUAS environment
+dnl variable.  The variable POFILES is set to the complete list of .po files,
+dnl according to the LINGUAS file in the po directory.  The variable MOFILES
+dnl is set to the list of .mo files that the user has requested be installed.
+dnl Both POFILES and MOFILES are AC_SUBSTed.
+dnl
+dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+dnl This is free software: you are free to do what the fuck you want to.
+dnl There is NO WARRANTY, to the extent permitted by law.
+
+AC_DEFUN([DX_LINGUAS], [dnl
+AC_REQUIRE([AM_GNU_GETTEXT])
+
+POFILES=
+MOFILES=
+
+if test -f "$srcdir/po/LINGUAS"; then
+       ALL_LINGUAS=`sed 's/#.*$//' "$srcdir/po/LINGUAS"`
+
+       : ${LINGUAS=all}
+       if test x"$LINGUAS" != x"all"; then
+               # Replicate la_CC-style codes as la.
+               LINGUAS=`printf '%s\n' "$LINGUAS" \
+                       | [sed 's/\([^_[:space:]]*\)_[^[:space:]]*/& \1/g']`
+
+               printf '%s\n' $ALL_LINGUAS | sort > conftest.LINGUAS
+               LINGUAS=`printf '%s\n' $LINGUAS | sort \
+                       | join - conftest.LINGUAS`
+       else
+               LINGUAS=$ALL_LINGUAS
+       fi
+
+       # Note: $srcdir is not used here because these variables are for make.
+       set x $ALL_LINGUAS; shift
+       case ${#} in
+       0) ;;
+       *) POFILES=`printf "po/%s.po\n" "${@}"` ;;
+       esac
+
+       if test x"$USE_NLS" = x"yes"; then
+               set x $LINGUAS; shift
+               case ${#} in
+               0) ;;
+               *) MOFILES=`printf "po/%s.mo\n" "${@}"` ;;
+               esac
+       fi
+fi
+
+AC_SUBST([POFILES])
+AC_SUBST([MOFILES])
+])
diff --git a/snippet/gettext.mk b/snippet/gettext.mk
new file mode 100644 (file)
index 0000000..3800114
--- /dev/null
@@ -0,0 +1,57 @@
+# Copyright © 2011-2012 Nick Bowler
+#
+# Automake fragment to distribute and install gettext .po/.mo files, intended
+# for use in a non-recursive build setup.  This does not include rules to
+# generate the .pot file.  Two variables must be defined:
+#
+#   POFILES: the complete list of .po files included with the package, and
+#   MOFILES: the set of .mo files to be installed (a user-selected subset
+#            of the available options).
+#
+# One way to define these variables is to use the DX_LINGUAS autoconf macro
+# which normally accompanies this fragment.
+#
+# License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+# This is free software: you are free to do what the fuck you want to.
+# There is NO WARRANTY, to the extent permitted by law.
+
+ALL_MOFILES = $(POFILES:.po=.mo)
+EXTRA_DIST += po/LINGUAS $(POFILES) $(ALL_MOFILES)
+MAINTAINERCLEANFILES += $(ALL_MOFILES)
+
+.po.mo:
+       $(AM_V_at) $(MKDIR_P) $(@D)
+       $(AM_V_GEN) $(MSGFMT) $(MSGFMTFLAGS) -c -o $@ $<
+
+install-data-local: install-mofiles
+install-mofiles: $(MOFILES)
+       for mo in $?; do \
+               lang=`expr "$$mo" : '.*/\(.*\)\.mo' \| "$$mo" : '\(.*\)\.mo'`; \
+               test x"$$lang" = x"" && exit 1; \
+               inst="$(DESTDIR)$(localedir)/$$lang/LC_MESSAGES"; \
+               (set -x; $(MKDIR_P) "$$inst") \
+                       || exit $$?; \
+               (set -x; $(INSTALL_DATA) "$$mo" "$$inst/$(PACKAGE).mo") \
+                       || exit $$?; \
+       done
+.PHONY: install-mofiles
+
+installdirs-local: installdirs-mofiles
+installdirs-mofiles:
+       for mo in $(MOFILES); do \
+               lang=`expr "$$mo" : '.*/\(.*\)\.mo' \| "$$mo" : '\(.*\)\.mo'`; \
+               test x"$$lang" = x"" && exit 1; \
+               inst="$(DESTDIR)$(localedir)/$$lang/LC_MESSAGES"; \
+               (set -x; $(MKDIR_P) "$$inst") || exit $$?; \
+       done
+.PHONY: installdirs-mofiles
+
+uninstall-local: uninstall-mofiles
+uninstall-mofiles:
+       for mo in $(ALL_MOFILES); do \
+               lang=`expr "$$mo" : '.*/\(.*\)\.mo' \| "$$mo" : '\(.*\)\.mo'`; \
+               test x"$$lang" = x"" && exit 1; \
+               inst="$(DESTDIR)$(localedir)/$$lang/LC_MESSAGES"; \
+               (set -x; cd "$$inst" && rm -f '$(PACKAGE).mo'); \
+       done
+.PHONY: uninstall-mofiles