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:
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.pot"
31 : ${XGETTEXT=xgettext}
32 ${XGETTEXT} -o prog.pot
--omit-header --no-location prog.py
34 tmpfiles
="$tmpfiles prog.ok"
36 msgid "'Your command, please?', asked the waiter."
40 msgid "a piece of cake"
41 msgid_plural "%(count)d pieces of cake"
46 msgid "%(oldCurrency)s is replaced by %(newCurrency)s."
51 ${DIFF} prog.ok prog.pot ||
exit 1
53 tmpfiles
="$tmpfiles fr.po"
57 "Content-Type: text/plain; charset=ISO-8859-1\n"
58 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
60 msgid
"'Your command, please?', asked the waiter."
61 msgstr
"«Votre commande, s'il vous plait», dit le garçon."
63 # Les gateaux allemands sont les meilleurs du monde.
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"
70 # Reverse the arguments.
72 msgid
"%(oldCurrency)s is replaced by %(newCurrency)s."
73 msgstr
"%(newCurrency)s remplace %(oldCurrency)s."
76 tmpfiles
="$tmpfiles fr.po.new"
77 : ${MSGMERGE=msgmerge}
78 ${MSGMERGE} -q -o fr.po.new fr.po prog.pot
81 ${DIFF} fr.po fr.po.new ||
exit 1
83 tmpfiles
="$tmpfiles fr"
84 test -d fr || mkdir fr
85 test -d fr
/LC_MESSAGES || mkdir fr
/LC_MESSAGES
88 ${MSGFMT} -o fr
/LC_MESSAGES
/prog.mo fr.po
90 # Test for presence of python version 2.3 or newer.
91 (python
-V) >/dev
/null
2>/dev
/null \
92 ||
{ rm -fr $tmpfiles; exit 77; }
93 case `python -c 'import sys; print sys.hexversion >= 0x20300F0'` in
95 *) rm -fr $tmpfiles; exit 77;;
98 tmpfiles
="$tmpfiles prog.ok prog.oku prog.out"
101 «Votre commande
, s
'il vous plait», dit le garçon.
105 cat <<\EOF > prog.oku
106 «Votre commande, s'il vous plait»
, dit le garçon.
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
117 if test $LOCALE_FR_UTF8 != none
; then
118 LANGUAGE
= LC_ALL
=$LOCALE_FR_UTF8 python prog.py
2 > prog.out ||
exit 1
119 ${DIFF} prog.oku prog.out ||
exit 1
121 if test $LOCALE_FR = none
&& test $LOCALE_FR_UTF8 = none
; then
122 rm -fr $tmpfiles; exit 77