1#! /bin/sh 2. "${srcdir=.}/init.sh"; path_prepend_ . ../src 3 4# Test of gettext facilities in the C language. 5# Assumes an fr_FR locale is installed. 6# Assumes the following packages are installed: gcc. 7 8# This test fails if the gettext package was configured with --disable-nls, 9# because in this case the gettext-runtime/intl/ directory does not produce 10# a <libintl.h> header file. 11 12cat <<\EOF > prog.c 13#include "config.h" 14#include <libintl.h> 15#include <locale.h> 16#include <stdio.h> 17#include <stdlib.h> 18#include "xsetenv.h" 19#define _(string) gettext (string) 20 21int main (int argc, char *argv[]) 22{ 23 int n = atoi (argv[2]); 24 25 xsetenv ("LC_ALL", argv[1], 1); 26 if (setlocale (LC_ALL, "") == NULL) 27 /* Couldn't set locale. */ 28 exit (77); 29 30 textdomain ("prog"); 31 bindtextdomain ("prog", "."); 32 33 printf (_("'Your command, please?', asked the waiter.")); 34 printf ("\n"); 35 36 printf (ngettext ("a piece of cake", "%d pieces of cake", n), n); 37 printf ("\n"); 38 39 printf (_("%s is replaced by %s."), "FF", "EUR"); 40 printf ("\n"); 41 42 exit (0); 43} 44EOF 45 46# Put the -I flags before ${CFLAGS} ${CPPFLAGS}, to make sure that libintl.h 47# is found in the build directory, regardless of -I options present in 48# ${CFLAGS} or ${CPPFLAGS}. 49${CC} -I../.. -I"$abs_top_srcdir"/gnulib-lib -I../../intl ${CFLAGS} \ 50 ${CPPFLAGS} -c prog.c || Exit 1 51 52: ${CONFIG_SHELL=${SHELL-/bin/sh}} 53${CONFIG_SHELL} "$top_builddir"/libtool --quiet --tag=CC --mode=link \ 54 ${CC} ${CFLAGS} -o prog prog.${OBJEXT} \ 55 ../../gnulib-lib/libgettextlib.la ${LDFLAGS} ${LTLIBINTL} \ 56 || Exit 1 57 58: ${XGETTEXT=xgettext} 59${XGETTEXT} -o prog.tmp --omit-header --no-location -k_ prog.c || Exit 1 60LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || Exit 1 61 62cat <<EOF > prog.ok 63#, c-format 64msgid "'Your command, please?', asked the waiter." 65msgstr "" 66 67#, c-format 68msgid "a piece of cake" 69msgid_plural "%d pieces of cake" 70msgstr[0] "" 71msgstr[1] "" 72 73#, c-format 74msgid "%s is replaced by %s." 75msgstr "" 76EOF 77 78: ${DIFF=diff} 79${DIFF} prog.ok prog.pot || Exit 1 80 81cat <<\EOF > fr.po 82msgid "" 83msgstr "" 84"Content-Type: text/plain; charset=ISO-8859-1\n" 85"Plural-Forms: nplurals=2; plural=(n > 1);\n" 86 87#, c-format 88msgid "'Your command, please?', asked the waiter." 89msgstr "�Votre commande, s'il vous plait�, dit le gar�on." 90 91# Les gateaux allemands sont les meilleurs du monde. 92#, c-format 93msgid "a piece of cake" 94msgid_plural "%d pieces of cake" 95msgstr[0] "un morceau de gateau" 96msgstr[1] "%d morceaux de gateau" 97 98# Reverse the arguments. 99#, c-format 100msgid "%s is replaced by %s." 101msgstr "%2$s remplace %1$s." 102EOF 103 104: ${MSGMERGE=msgmerge} 105${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || Exit 1 106LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new || Exit 1 107 108: ${DIFF=diff} 109${DIFF} fr.po fr.po.new || Exit 1 110 111test -d fr || mkdir fr 112test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES 113 114: ${MSGFMT=msgfmt} 115${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po 116 117: ${DIFF=diff} 118cat <<\EOF > prog.ok 119�Votre commande, s'il vous plait�, dit le gar�on. 1202 morceaux de gateau 121EUR remplace FF. 122EOF 123cat <<\EOF > prog.oku 124«Votre commande, s'il vous plait», dit le garçon. 1252 morceaux de gateau 126EUR remplace FF. 127EOF 128 129: ${LOCALE_FR=fr_FR} 130: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 131if test $LOCALE_FR != none; then 132 prepare_locale_ fr $LOCALE_FR 133 LANGUAGE= ./prog $LOCALE_FR 2 > prog.tmp 134 case $? in 135 0) case "$host_os" in 136 mingw*) LC_ALL=C tr -d '\r' < prog.tmp > prog.out || Exit 1 ;; 137 *) cp prog.tmp prog.out || Exit 1 ;; 138 esac 139 ${DIFF} prog.ok prog.out || Exit 1;; 140 77) LOCALE_FR=none;; 141 *) Exit 1;; 142 esac 143fi 144if test $LOCALE_FR_UTF8 != none; then 145 prepare_locale_ fr $LOCALE_FR_UTF8 146 LANGUAGE= ./prog $LOCALE_FR_UTF8 2 > prog.tmp 147 case $? in 148 0) case "$host_os" in 149 mingw*) LC_ALL=C tr -d '\r' < prog.tmp > prog.out || Exit 1 ;; 150 *) cp prog.tmp prog.out || Exit 1 ;; 151 esac 152 ${DIFF} prog.oku prog.out || Exit 1;; 153 77) LOCALE_FR_UTF8=none;; 154 *) Exit 1;; 155 esac 156fi 157if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then 158 if test -f /usr/bin/localedef; then 159 echo "Skipping test: no french locale is installed" 160 else 161 echo "Skipping test: no french locale is supported" 162 fi 163 Exit 77 164fi 165 166Exit 0 167