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