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