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