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