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