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