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