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 11 tmpfiles="" 12 trap 'rm -fr $tmpfiles' 1 2 3 15 13 14 tmpfiles="$tmpfiles prog.awk" 15 cat <<\EOF > prog.awk 16 BEGIN { 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 } 26 EOF 27 28 tmpfiles="$tmpfiles prog.pot" 29 : ${XGETTEXT=xgettext} 30 ${XGETTEXT} -o prog.pot --omit-header --no-location prog.awk 31 32 tmpfiles="$tmpfiles prog.ok" 33 cat <<EOF > prog.ok 34 msgid "'Your command, please?', asked the waiter." 35 msgstr "" 36 37 #, awk-format 38 msgid "a piece of cake" 39 msgid_plural "%d pieces of cake" 40 msgstr[0] "" 41 msgstr[1] "" 42 43 #, awk-format 44 msgid "%s is replaced by %s." 45 msgstr "" 46 EOF 47 48 : ${DIFF=diff} 49 ${DIFF} prog.ok prog.pot || exit 1 50 51 tmpfiles="$tmpfiles fr.po" 52 cat <<\EOF > fr.po 53 msgid "" 54 msgstr "" 55 "Content-Type: text/plain; charset=ISO-8859-1\n" 56 "Plural-Forms: nplurals=2; plural=(n > 1);\n" 57 58 msgid "'Your command, please?', asked the waiter." 59 msgstr "Votre commande, s'il vous plait, dit le garon." 60 61 # Les gateaux allemands sont les meilleurs du monde. 62 #, awk-format 63 msgid "a piece of cake" 64 msgid_plural "%d pieces of cake" 65 msgstr[0] "un morceau de gateau" 66 msgstr[1] "%d morceaux de gateau" 67 68 # Reverse the arguments. 69 #, awk-format 70 msgid "%s is replaced by %s." 71 msgstr "%2$s remplace %1$s." 72 EOF 73 74 tmpfiles="$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 81 tmpfiles="$tmpfiles fr" 82 test -d fr || mkdir fr 83 test -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; } 91 case `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;; 94 esac 95 96 # Test which of the fr_FR locales are installed. 97 : ${LOCALE_FR=fr_FR} 98 : ${LOCALE_FR_UTF8=fr_FR.UTF-8} 99 if 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 106 fi 107 if 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 114 fi 115 if 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 122 fi 123 124 # Test that gawk wasn't built with --disable-nls. 125 : ${LOCALE_FR=fr_FR} 126 : ${LOCALE_FR_UTF8=fr_FR.UTF-8} 127 if 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 } 133 fi 134 if 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 } 140 fi 141 142 tmpfiles="$tmpfiles prog.ok prog.oku prog.out" 143 : ${DIFF=diff} 144 cat <<\EOF > prog.ok 145 Votre commande, s'il vous plait, dit le garon. 146 2 morceaux de gateau 147 EUR remplace FF. 148 EOF 149 cat <<\EOF > prog.oku 150 Votre commande, s'il vous plait, dit le garon. 151 2 morceaux de gateau 152 EUR remplace FF. 153 EOF 154 155 : ${LOCALE_FR=fr_FR} 156 : ${LOCALE_FR_UTF8=fr_FR.UTF-8} 157 if 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 160 fi 161 if 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 164 fi 165 166 rm -fr $tmpfiles 167 168 exit 0 169