1#! /bin/sh 2 3# Test of gettext facilities in the GNU awk language. 4# Assumes an fr_FR locale is installed. 5# Assumes the following packages are installed: gawk. 6 7# Note: This test fails on MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale 8# but not in the fr_FR.UTF-8 locale. Probably because in the fr_FR locale, 9# nl_langinfo(CODESET) returns "". 10 11tmpfiles="" 12trap 'rm -fr $tmpfiles' 1 2 3 15 13 14tmpfiles="$tmpfiles prog.awk" 15cat <<\EOF > prog.awk 16BEGIN { 17 TEXTDOMAIN = "prog" 18 bindtextdomain ("./") 19 20 print _"'Your command, please?', asked the waiter." 21 22 printf dcngettext ("a piece of cake", "%d pieces of cake", n) "\n", n 23 24 printf _"%s is replaced by %s." "\n", "FF", "EUR" 25} 26EOF 27 28tmpfiles="$tmpfiles prog.pot" 29: ${XGETTEXT=xgettext} 30${XGETTEXT} -o prog.pot --omit-header --no-location prog.awk 31 32tmpfiles="$tmpfiles prog.ok" 33cat <<EOF > prog.ok 34msgid "'Your command, please?', asked the waiter." 35msgstr "" 36 37#, awk-format 38msgid "a piece of cake" 39msgid_plural "%d pieces of cake" 40msgstr[0] "" 41msgstr[1] "" 42 43#, awk-format 44msgid "%s is replaced by %s." 45msgstr "" 46EOF 47 48: ${DIFF=diff} 49${DIFF} prog.ok prog.pot || exit 1 50 51tmpfiles="$tmpfiles fr.po" 52cat <<\EOF > fr.po 53msgid "" 54msgstr "" 55"Content-Type: text/plain; charset=ISO-8859-1\n" 56"Plural-Forms: nplurals=2; plural=(n > 1);\n" 57 58msgid "'Your command, please?', asked the waiter." 59msgstr "�Votre commande, s'il vous plait�, dit le gar�on." 60 61# Les gateaux allemands sont les meilleurs du monde. 62#, awk-format 63msgid "a piece of cake" 64msgid_plural "%d pieces of cake" 65msgstr[0] "un morceau de gateau" 66msgstr[1] "%d morceaux de gateau" 67 68# Reverse the arguments. 69#, awk-format 70msgid "%s is replaced by %s." 71msgstr "%2$s remplace %1$s." 72EOF 73 74tmpfiles="$tmpfiles fr.po.new" 75: ${MSGMERGE=msgmerge} 76${MSGMERGE} -q -o fr.po.new fr.po prog.pot 77 78: ${DIFF=diff} 79${DIFF} fr.po fr.po.new || exit 1 80 81tmpfiles="$tmpfiles fr" 82test -d fr || mkdir fr 83test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES 84 85: ${MSGFMT=msgfmt} 86${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po 87 88# Test for presence of gawk version 3.1.1 or newer. 89(gawk --version) >/dev/null 2>/dev/null \ 90 || { rm -fr $tmpfiles; exit 77; } 91case `gawk --version 2>&1 | sed -e 's/^[^0-9]*//'` in 92 0.* | 1.* | 2.* | 3.0* | 3.1.0*) 93 rm -fr $tmpfiles; exit 77;; 94esac 95 96# Test which of the fr_FR locales are installed. 97: ${LOCALE_FR=fr_FR} 98: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 99if test $LOCALE_FR != none; then 100 LC_ALL=$LOCALE_FR ./testlocale 101 case $? in 102 0) ;; 103 77) LOCALE_FR=none;; 104 *) exit 1;; 105 esac 106fi 107if test $LOCALE_FR_UTF8 != none; then 108 LC_ALL=$LOCALE_FR_UTF8 ./testlocale 109 case $? in 110 0) ;; 111 77) LOCALE_FR_UTF8=none;; 112 *) exit 1;; 113 esac 114fi 115if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then 116 rm -fr $tmpfiles; exit 77 117fi 118 119# Test that gawk wasn't built with --disable-nls. 120: ${LOCALE_FR=fr_FR} 121: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 122if test $LOCALE_FR != none; then 123 LANGUAGE= LC_ALL=$LOCALE_FR gawk --version | grep logiciel > /dev/null 124 test $? = 0 || { rm -fr $tmpfiles; exit 77; } 125fi 126if test $LOCALE_FR_UTF8 != none; then 127 LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 gawk --version | grep logiciel > /dev/null 128 test $? = 0 || { rm -fr $tmpfiles; exit 77; } 129fi 130 131tmpfiles="$tmpfiles prog.ok prog.oku prog.out" 132: ${DIFF=diff} 133cat <<\EOF > prog.ok 134�Votre commande, s'il vous plait�, dit le gar�on. 1352 morceaux de gateau 136EUR remplace FF. 137EOF 138cat <<\EOF > prog.oku 139«Votre commande, s'il vous plait», dit le garçon. 1402 morceaux de gateau 141EUR remplace FF. 142EOF 143 144: ${LOCALE_FR=fr_FR} 145: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 146if test $LOCALE_FR != none; then 147 LANGUAGE= LC_ALL=$LOCALE_FR gawk -v n=2 -f prog.awk > prog.out || exit 1 148 ${DIFF} prog.ok prog.out || exit 1 149fi 150if test $LOCALE_FR_UTF8 != none; then 151 LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 gawk -v n=2 -f prog.awk > prog.out || exit 1 152 ${DIFF} prog.oku prog.out || exit 1 153fi 154 155rm -fr $tmpfiles 156 157exit 0 158