From fa7d434b5a41d4c6ec128116c9e09c36881f1467 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Wed, 18 Mar 2009 17:46:07 +0100 Subject: added gettext in testd, also added wolf gettext.c and initialization code --- include/wolf/port/gettext.h | 11 +++++++++ makefiles/gmake/platform.mk | 2 +- src/GNUmakefile | 3 ++- src/daemon/daemon.c | 1 + src/daemon/pidfile.c | 1 + src/daemon/signals.c | 1 + src/log/log.c | 1 + src/port/gettext.c | 45 ++++++++++++++++++++++++++++++++++++ tests/daemon/GNUmakefile | 8 +++++++ tests/daemon/po/de.po | 56 +++++++++++++++++++++++++++++++++++++++++++++ tests/daemon/testd.c | 9 +------- 11 files changed, 128 insertions(+), 10 deletions(-) create mode 100644 src/port/gettext.c create mode 100644 tests/daemon/po/de.po diff --git a/include/wolf/port/gettext.h b/include/wolf/port/gettext.h index 4fce1aa..93a37ff 100644 --- a/include/wolf/port/gettext.h +++ b/include/wolf/port/gettext.h @@ -57,6 +57,15 @@ extern char *libintl_gettext( const char *__msgid ) __attribute__ ( ( format_arg #include /* for setlocale */ +/** It's much easier to define a DEFAULT_TEXT_DOMAIN and map gettext to a + * dgettext, so that we don't have to call 'textdomain' anywhere in the + * library. Define this before including gettext.h + */ +#if defined DEFAULT_TEXT_DOMAIN +#undef gettext +#define gettext( msgid ) dgettext( DEFAULT_TEXT_DOMAIN, msgid ) +#endif /* defined DEFAULT_TEXT_DOMAIN */ + #else /* ENABLE_NLS */ #define gettext( msgid ) ( (const char *)( msgid ) ) @@ -75,6 +84,8 @@ extern char *libintl_gettext( const char *__msgid ) __attribute__ ( ( format_arg /* shorthand macro for lazy people */ #define _( s ) gettext( s ) +void wolf_port_initialize_i18n( const char *argv0, const char *app ); + /** @} */ /* @addtogroup wolf_port */ #endif /* ifndef WOLF_GETTEXT_H */ diff --git a/makefiles/gmake/platform.mk b/makefiles/gmake/platform.mk index f9d6ec7..b81ccbb 100644 --- a/makefiles/gmake/platform.mk +++ b/makefiles/gmake/platform.mk @@ -120,7 +120,7 @@ PLATFORM_COMPILE_FLAGS += $(INCLUDE_FLAGS_LT) endif PLATFORM_COMPILE_FLAGS += \ - -DENABLE_NLS=$(ENABLE_NLS) + -DENABLE_NLS=$(ENABLE_NLS) -DLOCALEDIR=\"$(localedir)\" # command line parser generator gengetopt ######################################## diff --git a/src/GNUmakefile b/src/GNUmakefile index 3099a43..9d11a38 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -10,7 +10,8 @@ PORT_OBJS = \ port/string.o \ port/unistd.o \ port/stdio.o \ - port/time.o + port/time.o \ + port/gettext.o LOG_OBJS = \ log/log.o diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 7c020ed..2be3524 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -3,6 +3,7 @@ #include "port/string.h" /* for strdup */ #include "port/limits.h" /* for PATH_MAX */ #include "port/noreturn.h" /* for NORETURN */ +#define DEFAULT_TEXT_DOMAIN "libwolf" #include "port/gettext.h" /* for i18n */ #include "errors.h" diff --git a/src/daemon/pidfile.c b/src/daemon/pidfile.c index 1af1117..bdf23e5 100644 --- a/src/daemon/pidfile.c +++ b/src/daemon/pidfile.c @@ -4,6 +4,7 @@ #include "port/stdbool.h" /* for bool */ #include "port/unistd.h" /* for getpid, open, write, read, * unlink, lockf */ +#define DEFAULT_TEXT_DOMAIN "libwolf" #include "port/gettext.h" /* for i18n */ #include "pidfile.h" diff --git a/src/daemon/signals.c b/src/daemon/signals.c index 9f46075..8a9a7c6 100644 --- a/src/daemon/signals.c +++ b/src/daemon/signals.c @@ -7,6 +7,7 @@ #include "daemon/signals.h" #include "port/unused.h" +#define DEFAULT_TEXT_DOMAIN "libwolf" #include "port/gettext.h" /* for i18n */ #include /* for getpid, pipe, write, read */ diff --git a/src/log/log.c b/src/log/log.c index ea18e8c..9aad099 100644 --- a/src/log/log.c +++ b/src/log/log.c @@ -24,6 +24,7 @@ #include "port/time.h" /* for localtime_r, strftime, time * time_t, struct tm */ #include "port/unused.h" /* for WOLF_UNUSED */ +#define DEFAULT_TEXT_DOMAIN "libwolf" #include "port/gettext.h" /* for i18n */ #include /* for variable arguments */ diff --git a/src/port/gettext.c b/src/port/gettext.c new file mode 100644 index 0000000..7c52ad0 --- /dev/null +++ b/src/port/gettext.c @@ -0,0 +1,45 @@ +/* + Copyright (C) 2008 Andreas Baumann + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "port/gettext.h" +#include "port/unused.h" + +#include /* for getenv */ + +void wolf_port_initialize_i18n( const char *argv0, const char *app ) { + const char *localedir; + + WOLF_UNUSED( argv0 ); + + /* default is the location $(localedir) points to (the final installation + * destination) + */ + localedir = LOCALEDIR; + + /* we can override the locale dir (very handy, so we can test as translator + * or relocate the locale dir without bothering root) + */ + if( getenv( "WOLFLOCALEDIR" ) != NULL ) { + localedir = getenv( "WOLFLOCALEDIR" ); + } + + /* respect locale setting from the shell */ + setlocale( LC_ALL, "" ); + + bindtextdomain( app, localedir ); + textdomain( app ); +} diff --git a/tests/daemon/GNUmakefile b/tests/daemon/GNUmakefile index 1ec54b3..d352fbd 100644 --- a/tests/daemon/GNUmakefile +++ b/tests/daemon/GNUmakefile @@ -13,6 +13,14 @@ TEST_BINS = \ TEST_OBJS = \ testd_cmdline.o +CATALOG_NAME = testd + +GETTEXT_LANGUAGES = de + +GETTEXT_FILES = $(TEST_OBJS:.o=.c) $(TEST_BINS:$(EXE)=.c) + +GETTEXT_TRIGGERS = _ gettext_noop gettext + -include $(TOPDIR)/makefiles/gmake/sub.mk # ABa: currently a special rule for cmdline.c as gengetopt is not diff --git a/tests/daemon/po/de.po b/tests/daemon/po/de.po new file mode 100644 index 0000000..effbdbe --- /dev/null +++ b/tests/daemon/po/de.po @@ -0,0 +1,56 @@ +# Copyright (C) 2008 Andreas Baumann +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +msgid "" +msgstr "" +"Project-Id-Version: libwolf 0.0.1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-03-18 17:40+0100\n" +"PO-Revision-Date: 2009-03-18 11:07+0100\n" +"Last-Translator: Andreas Baumann \n" +"Language-Team: German\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=iso-8859-1\n" +"Content-Transfer-Encoding: 8bit\n" + +#: testd.c:50 +#, c-format +msgid "Testing configuraton read from '%s'" +msgstr "Teste die Konfiguration von '%s'" + +#: testd.c:145 +#, c-format +msgid "Started %s daemon" +msgstr "Prozess %s gestartet" + +#: testd.c:154 +#, c-format +msgid "Suspending on UNIX signal resulted in an error %d!" +msgstr "Fehler %d waehrend des Wartens auf ein UNIX signal!" + +#: testd.c:160 +msgid "Rereading configuration" +msgstr "Lese Konfiguration erneut" + +#: testd.c:166 +msgid "Got termination signal, shutting down the daemon" +msgstr "Signal zum Beenden empfangen, stoppe jetzt den Prozess" + +#: testd.c:177 +#, fuzzy, c-format +msgid "Unexpected signal '%s' (%s, %d)" +msgstr "Unerwartetes Signal '%s' (%s)" + +#: testd.c:184 +#, c-format +msgid "Stopped %s daemon" +msgstr "Process %s gestoppt" diff --git a/tests/daemon/testd.c b/tests/daemon/testd.c index 3f9f5d2..7530d97 100644 --- a/tests/daemon/testd.c +++ b/tests/daemon/testd.c @@ -72,12 +72,6 @@ static int read_config( const char *filename, struct gengetopt_args_info *args_i return EXIT_SUCCESS; } -/* FIXME: coreutils set it to automake variables, see what postgres does and maybe - * set it in platform.mk? - */ -//#define LOCALEDIR "/usr/share/locale" -#define LOCALEDIR "locale" - int main( int argc, char *argv[] ) { struct gengetopt_args_info args_info; wolf_error_t error; @@ -85,8 +79,7 @@ int main( int argc, char *argv[] ) { wolf_daemon_p demon = NULL; int sig = 0; - setlocale( LC_ALL, "" ); - bindtextdomain( CMDLINE_PARSER_PACKAGE, LOCALEDIR ); + wolf_port_initialize_i18n( argv[0], CMDLINE_PARSER_PACKAGE ); if( parse_options_and_arguments( argc, argv, &args_info ) == EXIT_FAILURE ) { exit( EXIT_FAILURE ); -- cgit v1.2.3-54-g00ecf