From cc8367f974cc1c3b8d8f301c7916231135414d63 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 5 Nov 2011 10:24:42 +0100 Subject: gettext is in i18n now, has nothing to do with porting --- include/wolf/i18n/gettext.h | 93 ++++++++++++++++++++++++++++++++++++ include/wolf/port/gettext.h | 93 ------------------------------------ src/i18n/gettext.c | 50 +++++++++++++++++++ src/port/gettext.c | 50 ------------------- tests/gettext/GNUmakefile | 95 ------------------------------------- tests/gettext/test_gettext.c | 86 --------------------------------- tests/gettext/test_gettext.pot | 26 ---------- tests/gettext/test_gettext_de.po | 25 ---------- tests/gettext/test_gettext_de_CH.po | 25 ---------- tests/i18n/GNUmakefile | 95 +++++++++++++++++++++++++++++++++++++ tests/i18n/test_gettext.c | 86 +++++++++++++++++++++++++++++++++ tests/i18n/test_gettext.pot | 26 ++++++++++ tests/i18n/test_gettext_de.po | 25 ++++++++++ tests/i18n/test_gettext_de_CH.po | 25 ++++++++++ 14 files changed, 400 insertions(+), 400 deletions(-) create mode 100644 include/wolf/i18n/gettext.h delete mode 100644 include/wolf/port/gettext.h create mode 100644 src/i18n/gettext.c delete mode 100644 src/port/gettext.c delete mode 100644 tests/gettext/GNUmakefile delete mode 100644 tests/gettext/test_gettext.c delete mode 100644 tests/gettext/test_gettext.pot delete mode 100644 tests/gettext/test_gettext_de.po delete mode 100644 tests/gettext/test_gettext_de_CH.po create mode 100644 tests/i18n/GNUmakefile create mode 100644 tests/i18n/test_gettext.c create mode 100644 tests/i18n/test_gettext.pot create mode 100644 tests/i18n/test_gettext_de.po create mode 100644 tests/i18n/test_gettext_de_CH.po diff --git a/include/wolf/i18n/gettext.h b/include/wolf/i18n/gettext.h new file mode 100644 index 0000000..3d4a4f9 --- /dev/null +++ b/include/wolf/i18n/gettext.h @@ -0,0 +1,93 @@ +/* + 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 . +*/ + +#ifndef WOLF_GETTEXT_H +#define WOLF_GETTEXT_H + +/** + * @addtogroup wolf_port Porting + * @{ + */ + +/** + * @file gettext.h + * @brief localization header, nivelating some problems in gettext/libintl + * @author Andreas Baumann + */ + +/* some distributors like to disable NLS */ +#if ENABLE_NLS + +/* Some older versions of libintl.h make tests for the value __APPLE_CC though + * this macro can be undefined! Nice, defining it here as 0. + * (Noticed on OpenBSD 4.3) + */ +#if !defined( __APPLE_CC ) +#define __APPLE_CC__ 0 +#endif + +/* define a proper prototype with format_arg so that gcc doesn't croak. This + * is a problem on systems which have an onlder libintl.h where the declarations + * are missing. So we define a first prototype here and hope the compiler survives + * the redefiniton in libintl.h but for a format_arg (urgh!). Experienced only + * on NetBSD 4.1 + */ +#if defined __GNUC__ +#if defined GETTEXT_NEEDS_FORMAT_ARG +char *gettext( const char *__msgid ) __attribute__ ( ( format_arg ( 1 ) ) ); +char *libintl_gettext( const char *__msgid ) __attribute__ ( ( format_arg ( 1 ) ) ); +char *dgettext( const char *__domainname, const char *__msgid ) __attribute__ ( ( format_arg ( 2 ) ) ); +char *libintl_dgettext( const char *__domainname, const char *__msgid ) __attribute__ ( ( format_arg ( 2 ) ) ); +#endif +#endif + +#include /* for gettext, bindtextdomain */ + +#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 ) ) +#define LC_ALL 1 +#define setlocale( category, loc ) ( NULL ) +#define bindtextdomain( domain, directory ) ( NULL ) +#define textdomain( domain )( NULL ) + +#endif /* ENABLE_NLS */ + +/* a noop marker which let's xgettext extract the message but doesn't + * call the gettext() function if NLS is enabled. + */ +#define gettext_noop( s ) s + +/* 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/include/wolf/port/gettext.h b/include/wolf/port/gettext.h deleted file mode 100644 index 3d4a4f9..0000000 --- a/include/wolf/port/gettext.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - 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 . -*/ - -#ifndef WOLF_GETTEXT_H -#define WOLF_GETTEXT_H - -/** - * @addtogroup wolf_port Porting - * @{ - */ - -/** - * @file gettext.h - * @brief localization header, nivelating some problems in gettext/libintl - * @author Andreas Baumann - */ - -/* some distributors like to disable NLS */ -#if ENABLE_NLS - -/* Some older versions of libintl.h make tests for the value __APPLE_CC though - * this macro can be undefined! Nice, defining it here as 0. - * (Noticed on OpenBSD 4.3) - */ -#if !defined( __APPLE_CC ) -#define __APPLE_CC__ 0 -#endif - -/* define a proper prototype with format_arg so that gcc doesn't croak. This - * is a problem on systems which have an onlder libintl.h where the declarations - * are missing. So we define a first prototype here and hope the compiler survives - * the redefiniton in libintl.h but for a format_arg (urgh!). Experienced only - * on NetBSD 4.1 - */ -#if defined __GNUC__ -#if defined GETTEXT_NEEDS_FORMAT_ARG -char *gettext( const char *__msgid ) __attribute__ ( ( format_arg ( 1 ) ) ); -char *libintl_gettext( const char *__msgid ) __attribute__ ( ( format_arg ( 1 ) ) ); -char *dgettext( const char *__domainname, const char *__msgid ) __attribute__ ( ( format_arg ( 2 ) ) ); -char *libintl_dgettext( const char *__domainname, const char *__msgid ) __attribute__ ( ( format_arg ( 2 ) ) ); -#endif -#endif - -#include /* for gettext, bindtextdomain */ - -#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 ) ) -#define LC_ALL 1 -#define setlocale( category, loc ) ( NULL ) -#define bindtextdomain( domain, directory ) ( NULL ) -#define textdomain( domain )( NULL ) - -#endif /* ENABLE_NLS */ - -/* a noop marker which let's xgettext extract the message but doesn't - * call the gettext() function if NLS is enabled. - */ -#define gettext_noop( s ) s - -/* 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/src/i18n/gettext.c b/src/i18n/gettext.c new file mode 100644 index 0000000..5ab5b49 --- /dev/null +++ b/src/i18n/gettext.c @@ -0,0 +1,50 @@ +/* + 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 ); +#if !ENABLE_NLS + WOLF_UNUSED( app ); +#endif + + /* 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" ); + } + +#if ENABLE_NLS + /* respect locale setting from the shell */ + setlocale( LC_ALL, "" ); + + textdomain( app ); + bindtextdomain( app, localedir ); +#endif +} diff --git a/src/port/gettext.c b/src/port/gettext.c deleted file mode 100644 index 5ab5b49..0000000 --- a/src/port/gettext.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - 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 ); -#if !ENABLE_NLS - WOLF_UNUSED( app ); -#endif - - /* 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" ); - } - -#if ENABLE_NLS - /* respect locale setting from the shell */ - setlocale( LC_ALL, "" ); - - textdomain( app ); - bindtextdomain( app, localedir ); -#endif -} diff --git a/tests/gettext/GNUmakefile b/tests/gettext/GNUmakefile deleted file mode 100644 index c933f57..0000000 --- a/tests/gettext/GNUmakefile +++ /dev/null @@ -1,95 +0,0 @@ -TOPDIR = ../.. - -SUBDIRS = - -INCLUDE_LIBS = \ - $(TOPDIR)/src/libwolf.a - -INCLUDE_DIRS = \ - -I$(TOPDIR)/include/wolf -I. - -TEST_BINS = \ - test_gettext$(EXE) - --include $(TOPDIR)/makefiles/gmake/sub.mk - -test_gettext: $(TOPDIR)/src/libwolf.a - -# create and update the template: -# xgettext --flag=_:1:pass-c-format -d test_gettext -s -o test_gettext.pot test_gettext.c -# -# initial creation of the translation table: -# msginit -l de_CH -o test_gettext_de_CH.po -i test_gettext.pot -# -# merge the changes into the translation tables keeping existing -# translations -# msgmerge -s -U test_gettext_de_CH.po test_gettext.pot -# -# compile message files into binary format: -# msgfmt -c -v -o test_gettext_de.mo test_gettext_de.po -# -# for running make sure (on ARCH at least, check out others): -# - edit /etc/locale.gen -# - locale-gen -# -# - NetBSD needs -lintl for linking, the LANG is defined different (only de) - -%.pot: %.c - xgettext -k_ --flag=_:1:pass-c-format -d test_gettext -s -o $@ $< - touch $@ - -test_gettext_de.po: test_gettext.pot - msgmerge -s -U $@ -i $< - touch $@ - -test_gettext_de_CH.po: test_gettext.pot - msgmerge -s -U $@ -i $< - touch $@ - -%.mo : %.po - msgfmt -c -o $@ $< - -# TODO: big cleanup for GCC compilation flags -# in older gcc (before 4.2.1) we can't switch off warnings selectivly with a -# prage. So gettext misses a format attribute which results in a warning -# test_gettext.c:81: warning: format not a string literal, argument types not checked -# (Solaris 8, NetBSD) -# on Solaris 10 we get a system header conflict if we don't specify -std=c99 -#test_gettext.o : test_gettext.c -# $(CC) -c -g -o $@ $(PLATFORM_COMPILE_FLAGS) $(INCLUDE_DIRS) $< - -# LANG setting differs from platform to platform a little bit :-( -ifeq "$(PLATFORM)" "LINUX" -TEST_LANG = de_CH -endif -ifeq "$(PLATFORM)" "FREEBSD" -TEST_LANG = de_CH.ISO8859-1 -endif -ifeq "$(PLATFORM)" "OPENBSD" -TEST_LANG = de_CH.ISO8859-1 -endif -ifeq "$(PLATFORM)" "SUNOS" -TEST_LANG = de_CH.iso_8859_1 -endif -ifeq "$(PLATFORM)" "CYGWIN" -TEST_LANG = de -endif -ifeq "$(PLATFORM)" "NETBSD" -TEST_LANG = de -endif - -local_test: test_gettext_de.mo test_gettext_de_CH.mo - @echo "Testing gettext.." - @mkdir -p locale/de_CH/LC_MESSAGES - @mkdir -p locale/de/LC_MESSAGES - @cp test_gettext_de.mo locale/de_CH/LC_MESSAGES/test_gettext.mo - @cp test_gettext_de.mo locale/de/LC_MESSAGES/test_gettext.mo - @LANG=$(TEST_LANG) ./test_gettext >/dev/null 2>&1 - -local_all: - -local_clean: - @-rm -f *.mo - @-rm -rf locale - -local_distclean: diff --git a/tests/gettext/test_gettext.c b/tests/gettext/test_gettext.c deleted file mode 100644 index d5cb4c5..0000000 --- a/tests/gettext/test_gettext.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - 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/sys.h" - -#include "port/string.h" /* for strerror_r */ -#include "port/stdio.h" /* for puts, fprintf */ -#include /* for exit, EXIT_SUCCESS, free */ -#include /* for errno */ - -#include "port/gettext.h" /* for i18n */ - -int main( void ) { - char *loc; - char *bind_domain; - char *domain; - - /* respect locale settings of the environment */ - loc = setlocale( LC_ALL, "" ); - if( loc == NULL ) { - fprintf( stderr, "Warning, can't set locale, let's hope localization works nevertheless.\n" ); - } else { - printf( "Using locale %s\n", loc ); - } - - /* for testing here set the location of the message files, - * for standard installations this is /usr/share/locale - * (this we must do also for libraries, but just this) - */ - bind_domain = bindtextdomain( "test_gettext", "locale" ); - if( bind_domain == NULL ) { - char buf[1024]; - strerror_r( errno, buf, 1024 ); - fprintf( stderr, "Error setting gettext bind domain: %s (%d)\n", - buf, errno ); - } else { - printf( "Using bind domain %s\n", bind_domain ); - } - - /* set text domain so gettext function calls are retrieving the right - * string - */ - domain = textdomain( "test_gettext" ); - if( domain == NULL ) { - char buf[1024]; - strerror_r( errno, buf, 1024 ); - fprintf( stderr, "Error setting gettext domain: %s (%d)\n", - buf, errno ); - } else { - printf( "Using domain %s\n", domain ); - } - - /* dgettext instead of gettext in libraries? why? */ - - /* print something localized */ - puts( _( "A message without parameters" ) ); - - /* croaks in older gcc because the format string is used with a function - * without __attribute__ format definitions, this may also depend on the - * age of gettext and libintl? - */ - printf( _( "A message with two parameters, a string %s and an integer %d\n" ), - "string_param", 47 ); - - /* try POSIX positional arguments, gives a - * test_gettext.c:79: warning: ISO C does not support %n$ operand number formats */ -/* printf( _( "We must insert %1$d coins into %2$s" ), - 55, "the box" ); - */ - - return EXIT_SUCCESS; -} diff --git a/tests/gettext/test_gettext.pot b/tests/gettext/test_gettext.pot deleted file mode 100644 index 16cbc9a..0000000 --- a/tests/gettext/test_gettext.pot +++ /dev/null @@ -1,26 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-04-18 11:37+0200\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" - -#: test_gettext.c:76 -#, c-format -msgid "A message with two parameters, a string %s and an integer %d\n" -msgstr "" - -#: test_gettext.c:70 -msgid "A message without parameters" -msgstr "" diff --git a/tests/gettext/test_gettext_de.po b/tests/gettext/test_gettext_de.po deleted file mode 100644 index ca13feb..0000000 --- a/tests/gettext/test_gettext_de.po +++ /dev/null @@ -1,25 +0,0 @@ -# German translations for PACKAGE package. -# Copyright (C) 2009 THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# , 2009. -# -msgid "" -msgstr "Project-Id-Version: WolfBones 0.0.1\n" - "Report-Msgid-Bugs-To: \n" - "POT-Creation-Date: 2010-04-18 11:37+0200\n" - "PO-Revision-Date: 2009-03-09 09:33+0100\n" - "Last-Translator: \n" - "Language-Team: German\n" - "MIME-Version: 1.0\n" - "Content-Type: text/plain; charset=ASCII\n" - "Content-Transfer-Encoding: 8bit\n" - "Plural-Forms: nplurals=2; plural=(n != 1);\n" - -#: test_gettext.c:76 -#, c-format -msgid "A message with two parameters, a string %s and an integer %d\n" -msgstr "Eine Meldung mit einem String Parameter %s und einer Zahl %d\n" - -#: test_gettext.c:70 -msgid "A message without parameters" -msgstr "Eine Meldung ohne Parameter" diff --git a/tests/gettext/test_gettext_de_CH.po b/tests/gettext/test_gettext_de_CH.po deleted file mode 100644 index ca13feb..0000000 --- a/tests/gettext/test_gettext_de_CH.po +++ /dev/null @@ -1,25 +0,0 @@ -# German translations for PACKAGE package. -# Copyright (C) 2009 THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# , 2009. -# -msgid "" -msgstr "Project-Id-Version: WolfBones 0.0.1\n" - "Report-Msgid-Bugs-To: \n" - "POT-Creation-Date: 2010-04-18 11:37+0200\n" - "PO-Revision-Date: 2009-03-09 09:33+0100\n" - "Last-Translator: \n" - "Language-Team: German\n" - "MIME-Version: 1.0\n" - "Content-Type: text/plain; charset=ASCII\n" - "Content-Transfer-Encoding: 8bit\n" - "Plural-Forms: nplurals=2; plural=(n != 1);\n" - -#: test_gettext.c:76 -#, c-format -msgid "A message with two parameters, a string %s and an integer %d\n" -msgstr "Eine Meldung mit einem String Parameter %s und einer Zahl %d\n" - -#: test_gettext.c:70 -msgid "A message without parameters" -msgstr "Eine Meldung ohne Parameter" diff --git a/tests/i18n/GNUmakefile b/tests/i18n/GNUmakefile new file mode 100644 index 0000000..c933f57 --- /dev/null +++ b/tests/i18n/GNUmakefile @@ -0,0 +1,95 @@ +TOPDIR = ../.. + +SUBDIRS = + +INCLUDE_LIBS = \ + $(TOPDIR)/src/libwolf.a + +INCLUDE_DIRS = \ + -I$(TOPDIR)/include/wolf -I. + +TEST_BINS = \ + test_gettext$(EXE) + +-include $(TOPDIR)/makefiles/gmake/sub.mk + +test_gettext: $(TOPDIR)/src/libwolf.a + +# create and update the template: +# xgettext --flag=_:1:pass-c-format -d test_gettext -s -o test_gettext.pot test_gettext.c +# +# initial creation of the translation table: +# msginit -l de_CH -o test_gettext_de_CH.po -i test_gettext.pot +# +# merge the changes into the translation tables keeping existing +# translations +# msgmerge -s -U test_gettext_de_CH.po test_gettext.pot +# +# compile message files into binary format: +# msgfmt -c -v -o test_gettext_de.mo test_gettext_de.po +# +# for running make sure (on ARCH at least, check out others): +# - edit /etc/locale.gen +# - locale-gen +# +# - NetBSD needs -lintl for linking, the LANG is defined different (only de) + +%.pot: %.c + xgettext -k_ --flag=_:1:pass-c-format -d test_gettext -s -o $@ $< + touch $@ + +test_gettext_de.po: test_gettext.pot + msgmerge -s -U $@ -i $< + touch $@ + +test_gettext_de_CH.po: test_gettext.pot + msgmerge -s -U $@ -i $< + touch $@ + +%.mo : %.po + msgfmt -c -o $@ $< + +# TODO: big cleanup for GCC compilation flags +# in older gcc (before 4.2.1) we can't switch off warnings selectivly with a +# prage. So gettext misses a format attribute which results in a warning +# test_gettext.c:81: warning: format not a string literal, argument types not checked +# (Solaris 8, NetBSD) +# on Solaris 10 we get a system header conflict if we don't specify -std=c99 +#test_gettext.o : test_gettext.c +# $(CC) -c -g -o $@ $(PLATFORM_COMPILE_FLAGS) $(INCLUDE_DIRS) $< + +# LANG setting differs from platform to platform a little bit :-( +ifeq "$(PLATFORM)" "LINUX" +TEST_LANG = de_CH +endif +ifeq "$(PLATFORM)" "FREEBSD" +TEST_LANG = de_CH.ISO8859-1 +endif +ifeq "$(PLATFORM)" "OPENBSD" +TEST_LANG = de_CH.ISO8859-1 +endif +ifeq "$(PLATFORM)" "SUNOS" +TEST_LANG = de_CH.iso_8859_1 +endif +ifeq "$(PLATFORM)" "CYGWIN" +TEST_LANG = de +endif +ifeq "$(PLATFORM)" "NETBSD" +TEST_LANG = de +endif + +local_test: test_gettext_de.mo test_gettext_de_CH.mo + @echo "Testing gettext.." + @mkdir -p locale/de_CH/LC_MESSAGES + @mkdir -p locale/de/LC_MESSAGES + @cp test_gettext_de.mo locale/de_CH/LC_MESSAGES/test_gettext.mo + @cp test_gettext_de.mo locale/de/LC_MESSAGES/test_gettext.mo + @LANG=$(TEST_LANG) ./test_gettext >/dev/null 2>&1 + +local_all: + +local_clean: + @-rm -f *.mo + @-rm -rf locale + +local_distclean: diff --git a/tests/i18n/test_gettext.c b/tests/i18n/test_gettext.c new file mode 100644 index 0000000..d5cb4c5 --- /dev/null +++ b/tests/i18n/test_gettext.c @@ -0,0 +1,86 @@ +/* + 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/sys.h" + +#include "port/string.h" /* for strerror_r */ +#include "port/stdio.h" /* for puts, fprintf */ +#include /* for exit, EXIT_SUCCESS, free */ +#include /* for errno */ + +#include "port/gettext.h" /* for i18n */ + +int main( void ) { + char *loc; + char *bind_domain; + char *domain; + + /* respect locale settings of the environment */ + loc = setlocale( LC_ALL, "" ); + if( loc == NULL ) { + fprintf( stderr, "Warning, can't set locale, let's hope localization works nevertheless.\n" ); + } else { + printf( "Using locale %s\n", loc ); + } + + /* for testing here set the location of the message files, + * for standard installations this is /usr/share/locale + * (this we must do also for libraries, but just this) + */ + bind_domain = bindtextdomain( "test_gettext", "locale" ); + if( bind_domain == NULL ) { + char buf[1024]; + strerror_r( errno, buf, 1024 ); + fprintf( stderr, "Error setting gettext bind domain: %s (%d)\n", + buf, errno ); + } else { + printf( "Using bind domain %s\n", bind_domain ); + } + + /* set text domain so gettext function calls are retrieving the right + * string + */ + domain = textdomain( "test_gettext" ); + if( domain == NULL ) { + char buf[1024]; + strerror_r( errno, buf, 1024 ); + fprintf( stderr, "Error setting gettext domain: %s (%d)\n", + buf, errno ); + } else { + printf( "Using domain %s\n", domain ); + } + + /* dgettext instead of gettext in libraries? why? */ + + /* print something localized */ + puts( _( "A message without parameters" ) ); + + /* croaks in older gcc because the format string is used with a function + * without __attribute__ format definitions, this may also depend on the + * age of gettext and libintl? + */ + printf( _( "A message with two parameters, a string %s and an integer %d\n" ), + "string_param", 47 ); + + /* try POSIX positional arguments, gives a + * test_gettext.c:79: warning: ISO C does not support %n$ operand number formats */ +/* printf( _( "We must insert %1$d coins into %2$s" ), + 55, "the box" ); + */ + + return EXIT_SUCCESS; +} diff --git a/tests/i18n/test_gettext.pot b/tests/i18n/test_gettext.pot new file mode 100644 index 0000000..16cbc9a --- /dev/null +++ b/tests/i18n/test_gettext.pot @@ -0,0 +1,26 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-04-18 11:37+0200\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" + +#: test_gettext.c:76 +#, c-format +msgid "A message with two parameters, a string %s and an integer %d\n" +msgstr "" + +#: test_gettext.c:70 +msgid "A message without parameters" +msgstr "" diff --git a/tests/i18n/test_gettext_de.po b/tests/i18n/test_gettext_de.po new file mode 100644 index 0000000..ca13feb --- /dev/null +++ b/tests/i18n/test_gettext_de.po @@ -0,0 +1,25 @@ +# German translations for PACKAGE package. +# Copyright (C) 2009 THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# , 2009. +# +msgid "" +msgstr "Project-Id-Version: WolfBones 0.0.1\n" + "Report-Msgid-Bugs-To: \n" + "POT-Creation-Date: 2010-04-18 11:37+0200\n" + "PO-Revision-Date: 2009-03-09 09:33+0100\n" + "Last-Translator: \n" + "Language-Team: German\n" + "MIME-Version: 1.0\n" + "Content-Type: text/plain; charset=ASCII\n" + "Content-Transfer-Encoding: 8bit\n" + "Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: test_gettext.c:76 +#, c-format +msgid "A message with two parameters, a string %s and an integer %d\n" +msgstr "Eine Meldung mit einem String Parameter %s und einer Zahl %d\n" + +#: test_gettext.c:70 +msgid "A message without parameters" +msgstr "Eine Meldung ohne Parameter" diff --git a/tests/i18n/test_gettext_de_CH.po b/tests/i18n/test_gettext_de_CH.po new file mode 100644 index 0000000..ca13feb --- /dev/null +++ b/tests/i18n/test_gettext_de_CH.po @@ -0,0 +1,25 @@ +# German translations for PACKAGE package. +# Copyright (C) 2009 THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# , 2009. +# +msgid "" +msgstr "Project-Id-Version: WolfBones 0.0.1\n" + "Report-Msgid-Bugs-To: \n" + "POT-Creation-Date: 2010-04-18 11:37+0200\n" + "PO-Revision-Date: 2009-03-09 09:33+0100\n" + "Last-Translator: \n" + "Language-Team: German\n" + "MIME-Version: 1.0\n" + "Content-Type: text/plain; charset=ASCII\n" + "Content-Transfer-Encoding: 8bit\n" + "Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: test_gettext.c:76 +#, c-format +msgid "A message with two parameters, a string %s and an integer %d\n" +msgstr "Eine Meldung mit einem String Parameter %s und einer Zahl %d\n" + +#: test_gettext.c:70 +msgid "A message without parameters" +msgstr "Eine Meldung ohne Parameter" -- cgit v1.2.3-54-g00ecf