fix and test translations
authorHans Ulrich Niedermann <hun@n-dimensional.de>
Sat, 12 Mar 2005 04:01:12 +0000 (05:01 +0100)
committerHans Ulrich Niedermann <hun@n-dimensional.de>
Sat, 12 Mar 2005 04:01:12 +0000 (05:01 +0100)
configure.in
po/POTFILES.in
test/Makefile.am
test/nls/Makefile.am [new file with mode: 0644]
test/nls/check-nls.in [new file with mode: 0644]
test/nls/print-localedir.c [new file with mode: 0644]
test/nls/test-nls.c [new file with mode: 0644]

index 3531cfa..60feee2 100644 (file)
@@ -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
 ])
index 47933d2..f4e0324 100644 (file)
@@ -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
index 70a883a..5cfa8e5 100644 (file)
@@ -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 (file)
index 0000000..6473f5f
--- /dev/null
@@ -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 (file)
index 0000000..f484940
--- /dev/null
@@ -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 (file)
index 0000000..ab1392b
--- /dev/null
@@ -0,0 +1,11 @@
+#include "config.h"
+#include "i18n.h"
+
+#include <stdio.h>
+
+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 (file)
index 0000000..c9b32e3
--- /dev/null
@@ -0,0 +1,79 @@
+#include "config.h"
+
+#include "i18n.h"
+#include <locale.h>
+
+#include <stdio.h>
+#include <string.h>
+
+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 <localedir>\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;
+}