From fd2f45cf93bfbf10863011fb1a61fc08041c2f51 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Fri, 10 Jun 2011 18:17:12 +0000 Subject: [PATCH] Add localization infrastructure Adds build system logic, translation macros in k5-platform.h, and bindtextdomain calls in libkrb5 initialization. ticket: 6918 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24959 dc483132-0cff-0310-8789-dd5450dbe970 --- src/Makefile.in | 2 +- src/config/pre.in | 1 + src/configure.in | 7 +++++++ src/include/k5-err.h | 4 ---- src/include/k5-platform.h | 21 ++++++++++++++++++--- src/lib/krb5/Makefile.in | 2 +- src/lib/krb5/krb5_libinit.c | 2 ++ src/po/Makefile.in | 33 +++++++++++++++++++++++++++++++++ src/po/deps | 1 + src/po/en_US.po | 17 +++++++++++++++++ src/po/mit-krb5.pot | 17 +++++++++++++++++ 11 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 src/po/Makefile.in create mode 100644 src/po/deps create mode 100644 src/po/en_US.po create mode 100644 src/po/mit-krb5.pot diff --git a/src/Makefile.in b/src/Makefile.in index 769f964a1..1bf2671a2 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -15,7 +15,7 @@ SUBDIRS=util include lib \ plugins/preauth/pkinit \ plugins/preauth/encrypted_challenge \ kdc kadmin slave clients appl tests \ - config-files gen-manpages + config-files gen-manpages po WINSUBDIRS=include util lib ccapi windows clients appl BUILDTOP=$(REL). LOCALINCLUDES = -I$(srcdir) diff --git a/src/config/pre.in b/src/config/pre.in index de0864555..69548babf 100644 --- a/src/config/pre.in +++ b/src/config/pre.in @@ -216,6 +216,7 @@ KRB5_DB_MODULE_DIR = $(MODULE_DIR)/kdb KRB5_PA_MODULE_DIR = $(MODULE_DIR)/preauth KRB5_AD_MODULE_DIR = $(MODULE_DIR)/authdata KRB5_LIBKRB5_MODULE_DIR = $(MODULE_DIR)/libkrb5 +KRB5_LOCALEDIR = @localedir@ GSS_MODULE_DIR = @libdir@/gss KRB5_INCSUBDIRS = \ $(KRB5_INCDIR)/kadm5 \ diff --git a/src/configure.in b/src/configure.in index 547ff0514..6b69df909 100644 --- a/src/configure.in +++ b/src/configure.in @@ -66,6 +66,12 @@ AC_CHECK_LIB(util,main,[AC_DEFINE(HAVE_LIBUTIL,1,[Define if the util library is LIBUTIL=-lutil ]) AC_SUBST(LIBUTIL) + +AC_CHECK_HEADER(libintl.h, [ + AC_SEARCH_LIBS(dgettext, intl, [ + AC_DEFINE(ENABLE_NLS, 1, + [Define if translation functions should be used.])])]) + # for kdc AC_CHECK_HEADERS(syslog.h sys/sockio.h ifaddrs.h unistd.h) AC_CHECK_FUNCS(openlog syslog closelog strftime vsprintf vasprintf vsnprintf) @@ -1161,4 +1167,5 @@ dnl ccapi ccapi/lib ccapi/lib/unix ccapi/server ccapi/server/unix ccapi/test tests/verify tests/gssapi tests/dejagnu tests/threads tests/shlib tests/gss-threads tests/misc tests/mkeystash_compat util/gss-kernel-lib util/collected-client-lib + po ) diff --git a/src/include/k5-err.h b/src/include/k5-err.h index 483c5cd37..f9d5b0ce7 100644 --- a/src/include/k5-err.h +++ b/src/include/k5-err.h @@ -32,10 +32,6 @@ #ifndef K5_ERR_H #define K5_ERR_H -#ifndef _ -#define _(X) (X) -#endif - #if defined(_MSDOS) || defined(_WIN32) #include #endif diff --git a/src/include/k5-platform.h b/src/include/k5-platform.h index dd776e7ec..d8324839b 100644 --- a/src/include/k5-platform.h +++ b/src/include/k5-platform.h @@ -36,6 +36,7 @@ * + consistent getpwnam/getpwuid interfaces * + va_copy fudged if not provided * + [v]asprintf + * + _, N_, dgettext, bindtextdomain, setlocale (for localization) */ #ifndef K5_PLATFORM_H @@ -1010,9 +1011,23 @@ extern int krb5int_mkstemp(char *); extern void krb5int_zap(void *ptr, size_t len); -/* Fudge for future adoption of gettext or the like. */ -#ifndef _ -#define _(X) (X) +/* + * Localization macros. If we have gettext, define _ appropriately for + * translating a string. If we do not have gettext, define _, bindtextdomain, + * and setlocale as no-ops. N_ is always a no-op; it marks a string for + * extraction to pot files but does not translate it. + */ +#ifdef ENABLE_NLS +#include +#include +#define KRB5_TEXTDOMAIN "mit-krb5" +#define _(s) dgettext(KRB5_TEXTDOMAIN, s) +#else +#define _(s) s +#define dgettext(d, m) m +#define bindtextdomain(p, d) +#define setlocale(c, l) #endif +#define N_(s) s #endif /* K5_PLATFORM_H */ diff --git a/src/lib/krb5/Makefile.in b/src/lib/krb5/Makefile.in index 9b95c02ba..a63270a21 100644 --- a/src/lib/krb5/Makefile.in +++ b/src/lib/krb5/Makefile.in @@ -3,7 +3,7 @@ BUILDTOP=$(REL)..$(S).. LOCALINCLUDES = -I$(srcdir)/ccache -I$(srcdir)/keytab -I$(srcdir)/rcache -I$(srcdir)/os -I$(srcdir)/unicode SUBDIRS= error_tables asn.1 ccache keytab krb os rcache unicode WINSUBDIRS= $(SUBDIRS) posix -DEFS= +DEFS=-DLOCALEDIR=\"$(KRB5_LOCALEDIR)\" ##DOSBUILDTOP = ..\.. ##DOSLIBNAME=$(OUTPRE)krb5.lib diff --git a/src/lib/krb5/krb5_libinit.c b/src/lib/krb5/krb5_libinit.c index e7c046705..cb72d508a 100644 --- a/src/lib/krb5/krb5_libinit.c +++ b/src/lib/krb5/krb5_libinit.c @@ -41,6 +41,8 @@ int krb5int_lib_init(void) add_error_table(&et_asn1_error_table); add_error_table(&et_k524_error_table); + bindtextdomain(KRB5_TEXTDOMAIN, LOCALEDIR); + err = krb5int_rc_finish_init(); if (err) return err; diff --git a/src/po/Makefile.in b/src/po/Makefile.in new file mode 100644 index 000000000..fd71f92b5 --- /dev/null +++ b/src/po/Makefile.in @@ -0,0 +1,33 @@ +mydir=po +BUILDTOP=$(REL).. +VER=@PACKAGE_VERSION@ + +DOMAIN=mit-krb5 +POTFILE=$(srcdir)/$(DOMAIN).pot +XGETTEXT=xgettext --foreign-user --package-name=mit-krb5 \ + --package-version=$(VER) --copyright-holder=MIT +# This is a placeholder until we have an actual translation. +CATALOGS=en_US.mo + +.SUFFIXES: .po .mo +.po.mo: + msgfmt -o $@ $< + +all:: $(CATALOGS) + +update-po: csrcs + $(XGETTEXT) -k_ -kN_ -o $(POTFILE) -f csrcs + +csrcs: always + find $(top_srcdir) -name "*.c" -print > $@ + +always: + +install:: + for c in $(CATALOGS); do \ + lang=`basename $$c .mo`; \ + $(top_srcdir)/config/mkinstalldirs \ + $(DESTDIR)$(KRB5_LOCALEDIR)/$$lang/LC_MESSAGES; \ + install -c $$c \ + $(DESTDIR)$(KRB5_LOCALEDIR)/$$lang/LC_MESSAGES/$(DOMAIN).mo; \ + done diff --git a/src/po/deps b/src/po/deps new file mode 100644 index 000000000..2feac3c9d --- /dev/null +++ b/src/po/deps @@ -0,0 +1 @@ +# No dependencies here. diff --git a/src/po/en_US.po b/src/po/en_US.po new file mode 100644 index 000000000..7e11d679a --- /dev/null +++ b/src/po/en_US.po @@ -0,0 +1,17 @@ +# English translations for Kerberos 5 package. +# Copyright (C) 2011 MIT +# This file is distributed under the same license as the Kerberos 5 package. +# Greg Hudson , 2011. +# +msgid "" +msgstr "" +"Project-Id-Version: mit-krb5 1.10-prerelease\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2011-06-06 00:34-0400\n" +"PO-Revision-Date: 2011-06-06 00:35-0400\n" +"Last-Translator: Greg Hudson \n" +"Language-Team: English\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" diff --git a/src/po/mit-krb5.pot b/src/po/mit-krb5.pot new file mode 100644 index 000000000..caa907e84 --- /dev/null +++ b/src/po/mit-krb5.pot @@ -0,0 +1,17 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR MIT +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: mit-krb5 1.10-prerelease\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2011-06-06 00:34-0400\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" -- 2.26.2