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