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