lang-bash revision 1.1.1.1
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.pot prog.err"
29: ${XGETTEXT=xgettext}
30LC_MESSAGES=C LC_ALL= \
31${XGETTEXT} -o prog.pot --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; }
36
37tmpfiles="$tmpfiles prog.ok"
38cat <<\EOF > prog.ok
39msgid "'Your command, please?', asked the waiter."
40msgstr ""
41
42#, sh-format
43msgid "a piece of cake"
44msgid_plural "$n pieces of cake"
45msgstr[0] ""
46msgstr[1] ""
47EOF
48
49: ${DIFF=diff}
50${DIFF} prog.ok prog.pot || exit 1
51
52tmpfiles="$tmpfiles fr.po"
53cat <<\EOF > fr.po
54msgid ""
55msgstr ""
56"Content-Type: text/plain; charset=ISO-8859-1\n"
57"Plural-Forms: nplurals=2; plural=(n > 1);\n"
58
59msgid "'Your command, please?', asked the waiter."
60msgstr "�Votre commande, s'il vous plait�, dit le gar�on."
61
62# Les gateaux allemands sont les meilleurs du monde.
63#, sh-format
64msgid "a piece of cake"
65msgid_plural "$n pieces of cake"
66msgstr[0] "un morceau de gateau"
67msgstr[1] "$n morceaux de gateau"
68EOF
69
70tmpfiles="$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
77tmpfiles="$tmpfiles fr"
78test -d fr || mkdir fr
79test -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; }
87case `bash -c 'echo $BASH_VERSION'` in
88  [2-9].*) ;;
89  *) echo "Skipping test: bash version too old"; rm -fr $tmpfiles; exit 77;;
90esac
91
92# Test which of the fr_FR locales are installed.
93: ${LOCALE_FR=fr_FR}
94: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
95if 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
102fi
103if 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
110fi
111if 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
118fi
119
120tmpfiles="$tmpfiles prog.nok prog.ok prog.oku prog.out"
121# Expected result when bash is built without i18n support.
122cat <<\EOF > prog.nok
123'Your command, please?', asked the waiter.
1242 morceaux de gateau
125EOF
126# Expected result when bash is built with i18n support.
127cat <<\EOF > prog.ok
128Votre commande, s'il vous plait�, dit le gar�on.
1292 morceaux de gateau
130EOF
131cat <<\EOF > prog.oku
132��Votre commande, s'il vous plait��, dit le gar��on.
1332 morceaux de gateau
134EOF
135
136: ${LOCALE_FR=fr_FR}
137: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
138if 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
146fi
147if 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
155fi
156
157rm -fr $tmpfiles
158
159exit 0
160