3 # Test of gettext facilities (including plural handling) in the Python
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
11 trap 'rm -fr $tmpfiles' 1 2 3 15
13 tmpfiles="$tmpfiles prog.py"
20 gettext.textdomain('prog')
21 gettext.bindtextdomain('prog', '.')
23 print gettext.gettext("'Your command, please?', asked the waiter.")
24 print gettext.ngettext("a piece of cake","%(count)d pieces of cake",n) \
26 print gettext.gettext("%(oldCurrency)s is replaced by %(newCurrency)s.") \
27 % { 'oldCurrency': "FF", 'newCurrency' : "EUR" }
30 tmpfiles="$tmpfiles prog.tmp prog.pot"
31 : ${XGETTEXT=xgettext}
32 ${XGETTEXT} -o prog.tmp --omit-header --no-location prog.py
33 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
34 LC_ALL=C tr -d '\r' < prog.tmp > prog.pot
35 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
37 tmpfiles="$tmpfiles prog.ok"
39 msgid "'Your command, please?', asked the waiter."
43 msgid "a piece of cake"
44 msgid_plural "%(count)d pieces of cake"
49 msgid "%(oldCurrency)s is replaced by %(newCurrency)s."
54 ${DIFF} prog.ok prog.pot || exit 1
56 tmpfiles="$tmpfiles fr.po"
60 "Content-Type: text/plain; charset=ISO-8859-1\n"
61 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
63 msgid "'Your command, please?', asked the waiter."
64 msgstr "«Votre commande, s'il vous plait», dit le garçon."
66 # Les gateaux allemands sont les meilleurs du monde.
68 msgid "a piece of cake"
69 msgid_plural "%(count)d pieces of cake"
70 msgstr[0] "un morceau de gateau"
71 msgstr[1] "%(count)d morceaux de gateau"
73 # Reverse the arguments.
75 msgid "%(oldCurrency)s is replaced by %(newCurrency)s."
76 msgstr "%(newCurrency)s remplace %(oldCurrency)s."
79 tmpfiles="$tmpfiles fr.po.tmp fr.po.new"
80 : ${MSGMERGE=msgmerge}
81 ${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot
82 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
83 LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new
84 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
87 ${DIFF} fr.po fr.po.new || exit 1
89 tmpfiles="$tmpfiles fr"
90 test -d fr || mkdir fr
91 test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES
94 ${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po
96 # Test for presence of python version 2.3 or newer.
97 (python -V) >/dev/null 2>/dev/null \
98 || { echo "Skipping test: python not found"; rm -fr $tmpfiles; exit 77; }
99 case `python -c 'import sys; print sys.hexversion >= 0x20300F0'` in
101 *) echo "Skipping test: python version too old"; rm -fr $tmpfiles; exit 77;;
104 tmpfiles="$tmpfiles prog.ok prog.oku prog.out"
107 «Votre commande, s'il vous plait», dit le garçon.
111 cat <<\EOF > prog.oku
112 «Votre commande, s'il vous plait», dit le garçon.
118 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
119 if test $LOCALE_FR != none; then
120 LANGUAGE= LC_ALL=$LOCALE_FR python prog.py 2 > prog.out || exit 1
121 ${DIFF} prog.ok prog.out || exit 1
123 if test -z "$UTF8_LOCALE_UNSUPPORTED"; then
124 if test $LOCALE_FR_UTF8 != none; then
125 LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 python prog.py 2 > prog.out || exit 1
126 ${DIFF} prog.oku prog.out || exit 1
128 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
129 if test -f /usr/bin/localedef; then
130 echo "Skipping test: no french locale is installed"
132 echo "Skipping test: no french locale is supported"
134 rm -fr $tmpfiles; exit 77
137 if test $LOCALE_FR = none; then
138 if test -f /usr/bin/localedef; then
139 echo "Skipping test: no traditional french locale is installed"
141 echo "Skipping test: no traditional french locale is supported"
143 rm -fr $tmpfiles; exit 77