]> git.draconx.ca Git - cdecl99.git/commitdiff
Initial i18n infrastructure.
authorNick Bowler <nbowler@draconx.ca>
Wed, 14 Sep 2011 23:51:24 +0000 (19:51 -0400)
committerNick Bowler <nbowler@draconx.ca>
Wed, 14 Sep 2011 23:51:24 +0000 (19:51 -0400)
.gitignore
Makefile.am
configure.ac
m4/.gitignore
m4/gnulib-cache.m4
m4/linguas.m4 [new file with mode: 0644]
po/.gitignore [new file with mode: 0644]
po/LINGUAS [new file with mode: 0644]
po/en.po [new file with mode: 0644]
src/cdecl99.c

index bc85844d7643b2edce63960251de2cbc773d90fb..fca2b495c70bbdf6aaf0eb22649e721276ba8bcb 100644 (file)
@@ -22,3 +22,4 @@ Makefile.in
 /c++defs.h
 /lib
 /cdecl99
+/ABOUT-NLS
index 447fbbf58db338d448d8ef072ee17e7ddadcc249..7525ac055673bafd53c3918cc79f3f1a99a82b67 100644 (file)
@@ -8,7 +8,8 @@ ACLOCAL_AMFLAGS = -I m4
 
 SUBDIRS = lib .
 AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src \
-       -I$(top_builddir)/lib -I$(top_srcdir)/lib
+       -I$(top_builddir)/lib -I$(top_srcdir)/lib \
+       -DLOCALEDIR=\"$(localedir)\"
 
 MAINTAINERCLEANFILES = src/scan.c src/scan.h src/scan.stamp \
        src/parse.c src/parse.h src/parse.stamp
@@ -23,10 +24,13 @@ dist_man_MANS = doc/man/cdecl99.1 doc/man/libcdecl.3
 include_HEADERS = src/cdecl.h
 noinst_HEADERS = src/typemap.h src/output.h src/scan.h src/parse.h
 
+noinst_DATA = $(MOFILES)
+
 lib_LTLIBRARIES = libcdecl.la
 libcdecl_la_LDFLAGS = -export-symbols-regex '^cdecl_[[:lower:]]'
 libcdecl_la_SOURCES = src/scan.c src/parse.c src/parse-decl.c src/typemap.c \
        src/output.c src/explain.c src/declare.c
+libcdecl_la_LIBADD = $(LTLIBINTL)
 
 bin_PROGRAMS = cdecl99
 cdecl99_SOURCES = src/cdecl99.c
@@ -47,6 +51,36 @@ src/typenames.h: $(srcdir)/src/types.lst $(srcdir)/src/typenames.sed
                < $(srcdir)/src/types.lst > $@.tmp
        $(AM_V_at)mv -f $@.tmp $@
 
+# Supporting rules for gettext.
+ALL_MOFILES = $(POFILES:.po=.mo)
+EXTRA_DIST += po/$(PACKAGE).pot po/LINGUAS $(POFILES) $(ALL_MOFILES)
+MAINTAINERCLEANFILES += po/$(PACKAGE).pot $(ALL_MOFILES)
+XGETTEXT_OPTS = -D $(builddir) -D $(srcdir) --from-code=utf-8 \
+       --add-comments=TRANSLATORS: --foreign-user \
+       --package-name=$(PACKAGE) --package-version=$(PACKAGE_VERSION) \
+       --msgid-bugs-address=$(PACKAGE_BUGREPORT)
+
+po/$(PACKAGE).pot: $(SOURCES)
+       $(AM_V_at)$(MKDIR_P) $(@D)
+       $(AM_V_GEN)$(XGETTEXT) $(XGETTEXT_OPTS) -o $@ $(SOURCES)
+
+.po.mo:
+       $(AM_V_at)$(MKDIR_P) $(@D)
+       $(AM_V_GEN)$(MSGFMT) -c -o $@ $<
+
+install-data-hook: install-mo
+install-mo: $(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 $$?; \
+               $(INSTALL_DATA) "$$mo" "$$inst/$(PACKAGE).mo" || exit $$?; \
+               set +x; \
+       done
+.PHONY: install-mo
+
 # These are required to prevent the builtin lex/yacc rules from
 # superseding ours...
 src/scan.c src/scan.h: src/scan.stamp
index e749f5300ff7354b4bed2e10c0c118bbfa5d8b1f..88eb75f97f44d1e393233614bda545b40cffca5e 100644 (file)
@@ -9,7 +9,7 @@ AC_INIT([cdecl99], [0.1], [nbowler@draconx.ca])
 AC_CONFIG_HEADER([config.h])
 AC_CONFIG_MACRO_DIR([m4])
 
-AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
+AM_INIT_AUTOMAKE([-Wall foreign subdir-objects])
 AM_SILENT_RULES([yes])
 
 AC_PROG_CC_C99
@@ -18,6 +18,10 @@ gl_EARLY
 LT_INIT
 gl_INIT
 
+AM_GNU_GETTEXT([external])
+AM_GNU_GETTEXT_VERSION([0.18.1])
+DX_LINGUAS
+
 AC_ARG_VAR([FLEX], [Command to invoke flex.  Defaults to flex.])
 AC_ARG_VAR([FLEXFLAGS], [Additional options to pass to flex.])
 AC_CHECK_PROGS([FLEX], [flex], [flex])
index 377fc87f0b0b2517cef06a9036546df34cf51b10..b75134eb37a99a24ff3b9f6d2b9c81ea0d0d5a40 100644 (file)
@@ -1,17 +1,32 @@
 00gnulib.m4
+codeset.m4
 errno_h.m4
 extensions.m4
+fcntl-o.m4
 getdelim.m4
 getline.m4
 getopt.m4
+gettext.m4
+glibc2.m4
+glibc21.m4
 gnulib-common.m4
 gnulib-comp.m4
 gnulib-tool.m4
+iconv.m4
 include_next.m4
+intdiv0.m4
+intl.m4
+intldir.m4
+intlmacosx.m4
+intmax.m4
+inttypes-pri.m4
+inttypes_h.m4
+lcmessage.m4
 lib-ld.m4
 lib-link.m4
 lib-prefix.m4
 libtool.m4
+lock.m4
 longlong.m4
 ltoptions.m4
 ltsugar.m4
@@ -19,12 +34,23 @@ ltversion.m4
 lt~obsolete.m4
 malloc.m4
 multiarch.m4
+nls.m4
+po.m4
+printf-posix.m4
+progtest.m4
 readline.m4
 realloc.m4
+size_max.m4
 stddef_h.m4
 stdint.m4
+stdint_h.m4
 stdio_h.m4
 stdlib_h.m4
+threadlib.m4
+uintmax_t.m4
 unistd_h.m4
+visibility.m4
 warn-on-use.m4
 wchar_t.m4
+wint_t.m4
+xsize.m4
index fdf347b9b21c501b75380a05e363a117f9e4d6c7..bd81c4924f7ab2787475b4934294b3eb2bf84410 100644 (file)
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files getopt-gnu readline
+#   gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files getopt-gnu gettext readline
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([])
 gl_MODULES([
   getopt-gnu
+  gettext
   readline
 ])
 gl_AVOID([])
diff --git a/m4/linguas.m4 b/m4/linguas.m4
new file mode 100644 (file)
index 0000000..5577c8a
--- /dev/null
@@ -0,0 +1,51 @@
+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/$POSUB/LINGUAS"; then
+       ALL_LINGUAS=`sed 's/#.*$//' "$srcdir/$POSUB/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 "$POSUB/%s.po\n" "${@}"` ;;
+       esac
+
+       set x $LINGUAS; shift
+       case ${#} in
+       0) ;;
+       *) MOFILES=`printf "$POSUB/%s.mo\n" "${@}"` ;;
+       esac
+fi
+
+AC_SUBST([POFILES])
+AC_SUBST([MOFILES])
+])
diff --git a/po/.gitignore b/po/.gitignore
new file mode 100644 (file)
index 0000000..6e2d559
--- /dev/null
@@ -0,0 +1,2 @@
+*.pot
+*.mo
diff --git a/po/LINGUAS b/po/LINGUAS
new file mode 100644 (file)
index 0000000..c574d07
--- /dev/null
@@ -0,0 +1 @@
+en
diff --git a/po/en.po b/po/en.po
new file mode 100644 (file)
index 0000000..2a587de
--- /dev/null
+++ b/po/en.po
@@ -0,0 +1,22 @@
+# English translations for cdecl99 package.
+# This file is put in the public domain.
+# Nick Bowler <nbowler@draconx.ca>, 2011.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: cdecl99 0.1\n"
+"Report-Msgid-Bugs-To: nbowler@draconx.ca\n"
+"POT-Creation-Date: 2011-09-13 21:34-0400\n"
+"PO-Revision-Date: 2011-09-13 21:54-0400\n"
+"Last-Translator: Nick Bowler <nbowler@draconx.ca>\n"
+"Language-Team: English\n"
+"Language: en\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#. TRANSLATORS: (C) must *always* be translated as ©.
+#: src/cdecl99.c:46
+msgid "(C)"
+msgstr "©"
index 64b95f78cf38a2778dd5a20bad73efc43d45553b..fcd7f50b1bf8821a624d5c3f28c8ff318b712205 100644 (file)
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <errno.h>
 #include <getopt.h>
+#include <gettext.h>
 #include "readline.h"
 #include "cdecl.h"
 
@@ -41,7 +42,8 @@ static const struct option lopts[] = {
 static void print_version(void)
 {
        puts(PACKAGE_STRING);
-       puts("Copyright (C) 2011 Nick Bowler.");
+       /* TRANSLATORS: (C) must *always* be translated as ©. */
+       printf("Copyright %s 2011 Nick Bowler.\n", gettext("(C)"));
        puts("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.");
        puts("This is free software: you are free to change and redistribute it.");
        puts("There is NO WARRANTY, to the extent permitted by law.");
@@ -316,6 +318,11 @@ int main(int argc, char **argv)
        if (argc > 0)
                progname = argv[0];
 
+       /* Initialize gettext. */
+       setlocale(LC_ALL, "");
+       bindtextdomain(PACKAGE, LOCALEDIR);
+       textdomain(PACKAGE);
+
        while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
                switch (opt) {
                case 'q':