lang-python-2 revision 1.1 1 #! /bin/sh
2
3 # Test of gettext facilities (including plural handling) in the Python
4 # language.
5
6 # Note: This test fails with Python 2.3, 2.4 when an UTF-8 locale is present.
7 # It looks like a bug in Python's gettext.py. This here is a quick workaround:
8 UTF8_LOCALE_UNSUPPORTED=yes
9
10 tmpfiles=""
11 trap 'rm -fr $tmpfiles' 1 2 3 15
12
13 tmpfiles="$tmpfiles prog.py"
14 cat <<\EOF > prog.py
15 import sys
16 import gettext
17
18 n = int(sys.argv[1])
19
20 gettext.textdomain('prog')
21 gettext.bindtextdomain('prog', '.')
22
23 print gettext.gettext("'Your command, please?', asked the waiter.")
24 print gettext.ngettext("a piece of cake","%(count)d pieces of cake",n) \
25 % { 'count': n }
26 print gettext.gettext("%(oldCurrency)s is replaced by %(newCurrency)s.") \
27 % { 'oldCurrency': "FF", 'newCurrency' : "EUR" }
28 EOF
29
30 tmpfiles="$tmpfiles prog.pot"
31 : ${XGETTEXT=xgettext}
32 ${XGETTEXT} -o prog.pot --omit-header --no-location prog.py
33
34 tmpfiles="$tmpfiles prog.ok"
35 cat <<EOF > prog.ok
36 msgid "'Your command, please?', asked the waiter."
37 msgstr ""
38
39 #, python-format
40 msgid "a piece of cake"
41 msgid_plural "%(count)d pieces of cake"
42 msgstr[0] ""
43 msgstr[1] ""
44
45 #, python-format
46 msgid "%(oldCurrency)s is replaced by %(newCurrency)s."
47 msgstr ""
48 EOF
49
50 : ${DIFF=diff}
51 ${DIFF} prog.ok prog.pot || exit 1
52
53 tmpfiles="$tmpfiles fr.po"
54 cat <<\EOF > fr.po
55 msgid ""
56 msgstr ""
57 "Content-Type: text/plain; charset=ISO-8859-1\n"
58 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
59
60 msgid "'Your command, please?', asked the waiter."
61 msgstr "Votre commande, s'il vous plait, dit le garon."
62
63 # Les gateaux allemands sont les meilleurs du monde.
64 #, python-format
65 msgid "a piece of cake"
66 msgid_plural "%(count)d pieces of cake"
67 msgstr[0] "un morceau de gateau"
68 msgstr[1] "%(count)d morceaux de gateau"
69
70 # Reverse the arguments.
71 #, python-format
72 msgid "%(oldCurrency)s is replaced by %(newCurrency)s."
73 msgstr "%(newCurrency)s remplace %(oldCurrency)s."
74 EOF
75
76 tmpfiles="$tmpfiles fr.po.new"
77 : ${MSGMERGE=msgmerge}
78 ${MSGMERGE} -q -o fr.po.new fr.po prog.pot
79
80 : ${DIFF=diff}
81 ${DIFF} fr.po fr.po.new || exit 1
82
83 tmpfiles="$tmpfiles fr"
84 test -d fr || mkdir fr
85 test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES
86
87 : ${MSGFMT=msgfmt}
88 ${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po
89
90 # Test for presence of python version 2.3 or newer.
91 (python -V) >/dev/null 2>/dev/null \
92 || { echo "Skipping test: python not found"; rm -fr $tmpfiles; exit 77; }
93 case `python -c 'import sys; print sys.hexversion >= 0x20300F0'` in
94 1 | True) ;;
95 *) echo "Skipping test: python version too old"; rm -fr $tmpfiles; exit 77;;
96 esac
97
98 tmpfiles="$tmpfiles prog.ok prog.oku prog.out"
99 : ${DIFF=diff}
100 cat <<\EOF > prog.ok
101 Votre commande, s'il vous plait, dit le garon.
102 2 morceaux de gateau
103 EUR remplace FF.
104 EOF
105 cat <<\EOF > prog.oku
106 Votre commande, s'il vous plait, dit le garon.
107 2 morceaux de gateau
108 EUR remplace FF.
109 EOF
110
111 : ${LOCALE_FR=fr_FR}
112 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
113 if test $LOCALE_FR != none; then
114 LANGUAGE= LC_ALL=$LOCALE_FR python prog.py 2 > prog.out || exit 1
115 ${DIFF} prog.ok prog.out || exit 1
116 fi
117 if test -z "$UTF8_LOCALE_UNSUPPORTED"; then
118 if test $LOCALE_FR_UTF8 != none; then
119 LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 python prog.py 2 > prog.out || exit 1
120 ${DIFF} prog.oku prog.out || exit 1
121 fi
122 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
123 if test -f /usr/bin/localedef; then
124 echo "Skipping test: no french locale is installed"
125 else
126 echo "Skipping test: no french locale is supported"
127 fi
128 rm -fr $tmpfiles; exit 77
129 fi
130 else
131 if test $LOCALE_FR = none; then
132 if test -f /usr/bin/localedef; then
133 echo "Skipping test: no traditional french locale is installed"
134 else
135 echo "Skipping test: no traditional french locale is supported"
136 fi
137 rm -fr $tmpfiles; exit 77
138 fi
139 fi
140
141 rm -fr $tmpfiles
142
143 exit 0
144