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:
8LOCALE_FR_UTF8=none
9
10tmpfiles=""
11trap 'rm -fr $tmpfiles' 1 2 3 15
12
13tmpfiles="$tmpfiles prog.py"
14cat <<\EOF > prog.py
15import sys
16import gettext
17
18n = int(sys.argv[1])
19
20gettext.textdomain('prog')
21gettext.bindtextdomain('prog', '.')
22
23print gettext.gettext("'Your command, please?', asked the waiter.")
24print gettext.ngettext("a piece of cake","%(count)d pieces of cake",n) \
25      % { 'count': n }
26print gettext.gettext("%(oldCurrency)s is replaced by %(newCurrency)s.") \
27      % { 'oldCurrency': "FF", 'newCurrency' : "EUR" }
28EOF
29
30tmpfiles="$tmpfiles prog.pot"
31: ${XGETTEXT=xgettext}
32${XGETTEXT} -o prog.pot --omit-header --no-location prog.py
33
34tmpfiles="$tmpfiles prog.ok"
35cat <<EOF > prog.ok
36msgid "'Your command, please?', asked the waiter."
37msgstr ""
38
39#, python-format
40msgid "a piece of cake"
41msgid_plural "%(count)d pieces of cake"
42msgstr[0] ""
43msgstr[1] ""
44
45#, python-format
46msgid "%(oldCurrency)s is replaced by %(newCurrency)s."
47msgstr ""
48EOF
49
50: ${DIFF=diff}
51${DIFF} prog.ok prog.pot || exit 1
52
53tmpfiles="$tmpfiles fr.po"
54cat <<\EOF > fr.po
55msgid ""
56msgstr ""
57"Content-Type: text/plain; charset=ISO-8859-1\n"
58"Plural-Forms: nplurals=2; plural=(n > 1);\n"
59
60msgid "'Your command, please?', asked the waiter."
61msgstr "�Votre commande, s'il vous plait�, dit le gar�on."
62
63# Les gateaux allemands sont les meilleurs du monde.
64#, python-format
65msgid "a piece of cake"
66msgid_plural "%(count)d pieces of cake"
67msgstr[0] "un morceau de gateau"
68msgstr[1] "%(count)d morceaux de gateau"
69
70# Reverse the arguments.
71#, python-format
72msgid "%(oldCurrency)s is replaced by %(newCurrency)s."
73msgstr "%(newCurrency)s remplace %(oldCurrency)s."
74EOF
75
76tmpfiles="$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
83tmpfiles="$tmpfiles fr"
84test -d fr || mkdir fr
85test -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  || { rm -fr $tmpfiles; exit 77; }
93case `python -c 'import sys; print sys.hexversion >= 0x20300F0'` in
94  1 | True) ;;
95  *) rm -fr $tmpfiles; exit 77;;
96esac
97
98tmpfiles="$tmpfiles prog.ok prog.oku prog.out"
99: ${DIFF=diff}
100cat <<\EOF > prog.ok
101Votre commande, s'il vous plait�, dit le gar�on.
1022 morceaux de gateau
103EUR remplace FF.
104EOF
105cat <<\EOF > prog.oku
106��Votre commande, s'il vous plait��, dit le gar��on.
1072 morceaux de gateau
108EUR remplace FF.
109EOF
110
111: ${LOCALE_FR=fr_FR}
112: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
113if 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
116fi
117if 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
120fi
121if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
122  rm -fr $tmpfiles; exit 77
123fi
124
125rm -fr $tmpfiles
126
127exit 0
128