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