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