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