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