From c1c9c415ea6625f0d3bc01927f29822060c1081a Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Sat, 12 Mar 2005 05:01:12 +0100 Subject: [PATCH] fix and test translations --- configure.in | 7 ++-- po/POTFILES.in | 1 + test/Makefile.am | 2 ++ test/nls/Makefile.am | 15 +++++++++ test/nls/check-nls.in | 40 +++++++++++++++++++++++ test/nls/print-localedir.c | 11 +++++++ test/nls/test-nls.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 151 insertions(+), 4 deletions(-) create mode 100644 test/nls/Makefile.am create mode 100644 test/nls/check-nls.in create mode 100644 test/nls/print-localedir.c create mode 100644 test/nls/test-nls.c diff --git a/configure.in b/configure.in index 3531cfa..60feee2 100644 --- a/configure.in +++ b/configure.in @@ -60,10 +60,8 @@ AM_GNU_GETTEXT_VERSION([0.14.1]) AM_GNU_GETTEXT GP_GETTEXT_FLAGS -AC_DEFINE_UNQUOTED([LIBEXIF_LOCALEDIR],["${datadir}/locale"], - [The locale directory used with libexif translations]) -AC_DEFINE_UNQUOTED([LIBMNOTE_LOCALEDIR],["${datadir}/locale"], - [The locale directory used with libexif translations]) +AM_CFLAGS="$AM_CFLAGS -DLIBEXIF_LOCALEDIR=\\\"\$(datadir)/locale\\\"" +AM_CFLAGS="$AM_CFLAGS -DLIBMNOTE_LOCALEDIR=\\\"\$(datadir)/locale\\\"" dnl --------------------------------------------------------------------------- @@ -94,6 +92,7 @@ AC_CONFIG_FILES([ libexif/pentax/Makefile libjpeg/Makefile test/Makefile + test/nls/Makefile m4/Makefile libexif/libexif.pc ]) diff --git a/po/POTFILES.in b/po/POTFILES.in index 47933d2..f4e0324 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -8,3 +8,4 @@ libexif/olympus/mnote-olympus-tag.c libexif/olympus/mnote-olympus-entry.c libexif/pentax/mnote-pentax-tag.c libexif/pentax/mnote-pentax-entry.c +test/nls/test-nls.c diff --git a/test/Makefile.am b/test/Makefile.am index 70a883a..5cfa8e5 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,3 +1,5 @@ +SUBDIRS = nls + noinst_PROGRAMS = test-mem test-tree test-mnote test-value test_tree_LDADD = $(top_builddir)/libjpeg/libjpeg.la $(top_builddir)/libexif/libexif.la $(INTLLIBS) diff --git a/test/nls/Makefile.am b/test/nls/Makefile.am new file mode 100644 index 0000000..6473f5f --- /dev/null +++ b/test/nls/Makefile.am @@ -0,0 +1,15 @@ +nlstestscripts = check-nls.sh + +TESTS = $(nlstestscripts) + +check_SCRIPTS = $(nlstestscripts) + +check_PROGRAMS = test-nls print-localedir + +CLEANFILES = $(check_SCRIPTS) + +test_nls_LDADD = $(top_builddir)/libexif/libexif.la $(INTLLIBS) + +%.sh: %.in Makefile + sed 's|@top_builddir\@|$(top_builddir)|g;s|@localedir\@|$(localedir)|g' < $< > $@ + chmod +x $@ diff --git a/test/nls/check-nls.in b/test/nls/check-nls.in new file mode 100644 index 0000000..f484940 --- /dev/null +++ b/test/nls/check-nls.in @@ -0,0 +1,40 @@ +#!/bin/sh + +top_builddir="@top_builddir@" +localedir="@localedir@" + +destdir="$(pwd)/tmp-root" + +if test -d "${top_builddir}"; then :; else + echo "top_builddir \`${top_builddir}' not found" + exit 3 +fi + +echo -n "Test installation of translated messages..." +if (cd "${top_builddir}/po" && make DESTDIR="${destdir}" install > /dev/null 2>&1); then + echo " done." +else + echo " FAILED." + echo "Could not create test installation of translated messages" + exit 2 +fi + +binlocaledir="$(./print-localedir)" +mylocaledir="${destdir}${binlocaledir}" +if test -d "${destdir}${binlocaledir}"; then + echo "Test installation contains localedir \`${binlocaledir}'." +else + echo "localedir \`${binlocaledir}' does not exist" + exit 1 +fi + +testnls="./test-nls ${mylocaledir}" +if ${testnls}; then + echo "NLS test successful" + rm -rf "${destdir}" + exit 0 +else + echo "NLS test failed, not removing test installation from" + echo " ${destdir}" + exit 1 +fi diff --git a/test/nls/print-localedir.c b/test/nls/print-localedir.c new file mode 100644 index 0000000..ab1392b --- /dev/null +++ b/test/nls/print-localedir.c @@ -0,0 +1,11 @@ +#include "config.h" +#include "i18n.h" + +#include + +int main(int argc, char *argv[]) +{ + puts(LIBEXIF_LOCALEDIR); + puts("\n"); + return 0; +} diff --git a/test/nls/test-nls.c b/test/nls/test-nls.c new file mode 100644 index 0000000..c9b32e3 --- /dev/null +++ b/test/nls/test-nls.c @@ -0,0 +1,79 @@ +#include "config.h" + +#include "i18n.h" +#include + +#include +#include + +struct _testcase { + char *locale; + char *untranslated; + char *expected; +}; + +typedef struct _testcase testcase; + +static testcase testcases[] = { + { "C", + "[DO_NOT_TRANSLATE_THIS_MARKER]", + "[DO_NOT_TRANSLATE_THIS_MARKER]" }, + { "de", + "[DO_NOT_TRANSLATE_THIS_MARKER]", + "[DO_NOT_TRANSLATE_THIS_MARKER_de]" }, +}; + +int main(int argc, char *argv[]) +{ + char *localedir; + int i; + + if (argc != 2) { + puts("Syntax: test-nls \n"); + return 1; + } + + localedir = argv[1]; + + for (i=0; i < sizeof(testcases)/sizeof(testcases[0]); i++) { + char *locale = testcases[i].locale; + char *untranslated = testcases[i].untranslated; + char *expected = testcases[i].expected; + char *translation; + char *actual_locale; + + printf("setlocale to %s\n", locale); + actual_locale = setlocale(LC_MESSAGES, locale); + + if (actual_locale == NULL) { + fprintf(stderr, "Error: Cannot set locale to %s.\n", locale); + exit(4); + } + + printf("locale is now %s\n", actual_locale); + + puts("before translation"); + translation = dgettext(GETTEXT_PACKAGE, untranslated); + puts("after translation"); + + if (strcmp(expected, translation) != 0) { + fprintf(stderr, "# %s\n", N_("[DO_NOT_TRANSLATE_THIS_MARKER]")); + + fprintf(stderr, + "locale: %s\n" + "localedir: %s\n" + "untranslated: %s\n" + "expected: %s\n" + "translation: %s\n" + "Error: translation != expected\n", + locale, + localedir, + untranslated, + expected, + translation); + + return 1; + } + } + return 0; +} -- 2.7.4