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.3 or newer. 89(gawk --version) >/dev/null 2>/dev/null \ 90 || { echo "Skipping test: gawk not found"; 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* | 3.1.1* | 3.1.2*) 93 echo "Skipping test: gawk version too old"; 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 if test -f /usr/bin/localedef; then 117 echo "Skipping test: no french locale is installed" 118 else 119 echo "Skipping test: no french locale is supported" 120 fi 121 rm -fr $tmpfiles; exit 77 122fi 123 124# Test that gawk wasn't built with --disable-nls. 125: ${LOCALE_FR=fr_FR} 126: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 127if test $LOCALE_FR != none; then 128 LANGUAGE= LC_ALL=$LOCALE_FR gawk --version | grep logiciel > /dev/null 129 test $? = 0 || { 130 echo "Skipping test: gawk was built without i18n support" 131 rm -fr $tmpfiles; exit 77 132 } 133fi 134if test $LOCALE_FR_UTF8 != none; then 135 LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 gawk --version | grep logiciel > /dev/null 136 test $? = 0 || { 137 echo "Skipping test: gawk was built without i18n support" 138 rm -fr $tmpfiles; exit 77 139 } 140fi 141 142tmpfiles="$tmpfiles prog.ok prog.oku prog.out" 143: ${DIFF=diff} 144cat <<\EOF > prog.ok 145�Votre commande, s'il vous plait�, dit le gar�on. 1462 morceaux de gateau 147EUR remplace FF. 148EOF 149cat <<\EOF > prog.oku 150��Votre commande, s'il vous plait��, dit le gar��on. 1512 morceaux de gateau 152EUR remplace FF. 153EOF 154 155: ${LOCALE_FR=fr_FR} 156: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 157if test $LOCALE_FR != none; then 158 LANGUAGE= LC_ALL=$LOCALE_FR gawk -v n=2 -f prog.awk > prog.out || exit 1 159 ${DIFF} prog.ok prog.out || exit 1 160fi 161if test $LOCALE_FR_UTF8 != none; then 162 LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 gawk -v n=2 -f prog.awk > prog.out || exit 1 163 ${DIFF} prog.oku prog.out || exit 1 164fi 165 166rm -fr $tmpfiles 167 168exit 0 169