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