summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/wolf/port/gettext.h11
-rw-r--r--makefiles/gmake/platform.mk2
-rw-r--r--src/GNUmakefile3
-rw-r--r--src/daemon/daemon.c1
-rw-r--r--src/daemon/pidfile.c1
-rw-r--r--src/daemon/signals.c1
-rw-r--r--src/log/log.c1
-rw-r--r--src/port/gettext.c45
-rw-r--r--tests/daemon/GNUmakefile8
-rw-r--r--tests/daemon/po/de.po56
-rw-r--r--tests/daemon/testd.c9
11 files changed, 128 insertions, 10 deletions
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 <locale.h> /* 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 <unistd.h> /* 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 <stdarg.h> /* 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 <abaumann@yahoo.com>
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include "port/gettext.h"
+#include "port/unused.h"
+
+#include <stdlib.h> /* 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 <abaumann@yahoo.com>
+#
+# 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 <http://www.gnu.org/licenses/>.
+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 <abaumann@yahoo.com>\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 );