From: Nick Bowler Date: Wed, 14 Sep 2011 23:51:24 +0000 (-0400) Subject: Initial i18n infrastructure. X-Git-Tag: v1~118 X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/commitdiff_plain/98cc6bc446211682eab914023cf36c1bbd02f6d7 Initial i18n infrastructure. --- diff --git a/.gitignore b/.gitignore index bc85844..fca2b49 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ Makefile.in /c++defs.h /lib /cdecl99 +/ABOUT-NLS diff --git a/Makefile.am b/Makefile.am index 447fbbf..7525ac0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/configure.ac b/configure.ac index e749f53..88eb75f 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/m4/.gitignore b/m4/.gitignore index 377fc87..b75134e 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -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 diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4 index fdf347b..bd81c49 100644 --- a/m4/gnulib-cache.m4 +++ b/m4/gnulib-cache.m4 @@ -15,12 +15,13 @@ # 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 index 0000000..5577c8a --- /dev/null +++ b/m4/linguas.m4 @@ -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 index 0000000..6e2d559 --- /dev/null +++ b/po/.gitignore @@ -0,0 +1,2 @@ +*.pot +*.mo diff --git a/po/LINGUAS b/po/LINGUAS new file mode 100644 index 0000000..c574d07 --- /dev/null +++ b/po/LINGUAS @@ -0,0 +1 @@ +en diff --git a/po/en.po b/po/en.po new file mode 100644 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 , 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 \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 "©" diff --git a/src/cdecl99.c b/src/cdecl99.c index 64b95f7..fcd7f50 100644 --- a/src/cdecl99.c +++ b/src/cdecl99.c @@ -22,6 +22,7 @@ #include #include #include +#include #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 ."); 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':