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