summaryrefslogtreecommitdiff
path: root/tests/i18n
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2011-11-05 10:24:42 +0100
committerAndreas Baumann <abaumann@yahoo.com>2011-11-05 10:24:42 +0100
commitcc8367f974cc1c3b8d8f301c7916231135414d63 (patch)
tree3f64e9f32f7d9803fb162f6bc8862d55b6648acb /tests/i18n
parent7bf0ff7b79608d91f47dbe1519f783307dddf307 (diff)
downloadwolfbones-cc8367f974cc1c3b8d8f301c7916231135414d63.tar.gz
wolfbones-cc8367f974cc1c3b8d8f301c7916231135414d63.tar.bz2
gettext is in i18n now, has nothing to do with porting
Diffstat (limited to 'tests/i18n')
-rw-r--r--tests/i18n/GNUmakefile95
-rw-r--r--tests/i18n/test_gettext.c86
-rw-r--r--tests/i18n/test_gettext.pot26
-rw-r--r--tests/i18n/test_gettext_de.po25
-rw-r--r--tests/i18n/test_gettext_de_CH.po25
5 files changed, 257 insertions, 0 deletions
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 <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/sys.h"
+
+#include "port/string.h" /* for strerror_r */
+#include "port/stdio.h" /* for puts, fprintf */
+#include <stdlib.h> /* for exit, EXIT_SUCCESS, free */
+#include <errno.h> /* 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 <EMAIL@ADDRESS>, 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 <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\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.
+# <abaumann@yahoo.com>, 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: <abaumann@yahoo.com>\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.
+# <abaumann@yahoo.com>, 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: <abaumann@yahoo.com>\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"