1#! /bin/sh 2. "${srcdir=.}/init.sh"; path_prepend_ . ../src ../../gettext-runtime/src 3 4# Test of gettext facilities in the bash language. 5# Assumes an fr_FR locale is installed. 6# Assumes the following packages are installed: bash 2.0 or newer. 7 8# This test fails on MacOS X 10.5 because its 'bash' command is built with 9# an included intl directory without iconv support; hence it produces wrong 10# output when accessing any .mo file not generated from a .po file in UTF-8 11# encoding. 12 13# This test fails if the gettext package was configured with --disable-nls, 14# because in this case the gettext-runtime/src/gettext program does not do 15# any message catalog lookups. 16 17cat <<\EOF > prog.bash 18#! /bin/bash 19 20n=$1 21 22. gettext.sh 23 24TEXTDOMAIN=prog 25export TEXTDOMAIN 26TEXTDOMAINDIR=. 27export TEXTDOMAINDIR 28 29$echo $"'Your command, please?', asked the waiter." 30 31$echo "`eval_ngettext "a piece of cake" "\\$n pieces of cake" $n`" 32EOF 33 34: ${XGETTEXT=xgettext} 35LC_MESSAGES=C LC_ALL= \ 36${XGETTEXT} -o prog.tmp --omit-header --no-location prog.bash \ 37 >prog.err 2>&1 38result=$? 39cat prog.err | grep -v 'warning: the syntax \$"\.\.\." is deprecated due to security reasons' 40test $result = 0 || { Exit 1; } 41LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || Exit 1 42 43cat <<\EOF > prog.ok 44msgid "'Your command, please?', asked the waiter." 45msgstr "" 46 47#, sh-format 48msgid "a piece of cake" 49msgid_plural "$n pieces of cake" 50msgstr[0] "" 51msgstr[1] "" 52EOF 53 54: ${DIFF=diff} 55${DIFF} prog.ok prog.pot || Exit 1 56 57cat <<\EOF > fr.po 58msgid "" 59msgstr "" 60"Content-Type: text/plain; charset=ISO-8859-1\n" 61"Plural-Forms: nplurals=2; plural=(n > 1);\n" 62 63msgid "'Your command, please?', asked the waiter." 64msgstr "�Votre commande, s'il vous plait�, dit le gar�on." 65 66# Les gateaux allemands sont les meilleurs du monde. 67#, sh-format 68msgid "a piece of cake" 69msgid_plural "$n pieces of cake" 70msgstr[0] "un morceau de gateau" 71msgstr[1] "$n morceaux de gateau" 72EOF 73 74: ${MSGMERGE=msgmerge} 75${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || Exit 1 76LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new || Exit 1 77 78: ${DIFF=diff} 79${DIFF} fr.po fr.po.new || Exit 1 80 81test -d fr || mkdir fr 82test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES 83 84: ${MSGFMT=msgfmt} 85${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po 86 87# Test for presence of bash version 2.0 or newer. 88(bash -c :) >/dev/null 2>/dev/null \ 89 || { echo "Skipping test: bash not found"; Exit 77; } 90case `bash -c 'echo $BASH_VERSION'` in 91 [2-9].*) ;; 92 *) echo "Skipping test: bash version too old"; Exit 77;; 93esac 94 95# Test which of the fr_FR locales are installed. 96: ${LOCALE_FR=fr_FR} 97: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 98if test $LOCALE_FR != none; then 99 LC_ALL=$LOCALE_FR ../testlocale 100 case $? in 101 0) ;; 102 77) LOCALE_FR=none;; 103 *) Exit 1;; 104 esac 105fi 106if test $LOCALE_FR_UTF8 != none; then 107 LC_ALL=$LOCALE_FR_UTF8 ../testlocale 108 case $? in 109 0) ;; 110 77) LOCALE_FR_UTF8=none;; 111 *) Exit 1;; 112 esac 113fi 114if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then 115 if test -f /usr/bin/localedef; then 116 echo "Skipping test: no french locale is installed" 117 else 118 echo "Skipping test: no french locale is supported" 119 fi 120 Exit 77 121fi 122 123case "$host_os" in 124 darwin*) 125 if test $LOCALE_FR != none; then 126 LC_ALL=$LOCALE_FR bash --help \ 127 | grep '^Utilisation' > /dev/null 2>&1 || Exit 77 128 fi 129 if test $LOCALE_FR_UTF8 != none; then 130 LC_ALL=$LOCALE_FR_UTF8 bash --help \ 131 | grep '^Utilisation' > /dev/null 2>&1 || Exit 77 132 fi 133 ;; 134esac 135 136# Expected result when bash is built without i18n support. 137cat <<\EOF > prog.nok 138'Your command, please?', asked the waiter. 1392 morceaux de gateau 140EOF 141# Expected result when bash is built with i18n support. 142cat <<\EOF > prog.ok 143�Votre commande, s'il vous plait�, dit le gar�on. 1442 morceaux de gateau 145EOF 146cat <<\EOF > prog.oku 147«Votre commande, s'il vous plait», dit le garçon. 1482 morceaux de gateau 149EOF 150 151: ${LOCALE_FR=fr_FR} 152: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 153if test $LOCALE_FR != none; then 154 prepare_locale_ fr $LOCALE_FR 155 LANGUAGE= LC_ALL=$LOCALE_FR bash ./prog.bash 2 > prog.out || Exit 1 156 : ${DIFF=diff} 157 ${DIFF} prog.nok prog.out > /dev/null && { 158 echo "Skipping test: bash is built without i18n support" 159 Exit 77 160 } 161 ${DIFF} prog.ok prog.out || Exit 1 162fi 163if test $LOCALE_FR_UTF8 != none; then 164 prepare_locale_ fr $LOCALE_FR_UTF8 165 LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 bash ./prog.bash 2 > prog.out || Exit 1 166 : ${DIFF=diff} 167 ${DIFF} prog.nok prog.out > /dev/null && { 168 echo "Skipping test: bash is built without i18n support" 169 Exit 77 170 } 171 ${DIFF} prog.oku prog.out || Exit 1 172fi 173 174Exit 0 175