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.7 when an UTF-8 locale is present.
7# It looks like a bug in Python's gettext.py. This here is a quick workaround:
8UTF8_LOCALE_UNSUPPORTED=yes
9
10cat <<\EOF > prog1.py
11import gettext
12
13gettext.textdomain('prog')
14gettext.bindtextdomain('prog', '.')
15
16print gettext.gettext("'Your command, please?', asked the waiter.")
17print gettext.gettext("%(oldCurrency)s is replaced by %(newCurrency)s.") \
18      % { 'oldCurrency': "FF", 'newCurrency' : "EUR" }
19EOF
20
21: ${XGETTEXT=xgettext}
22${XGETTEXT} -o prog.tmp --omit-header --no-location prog1.py || Exit 1
23LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || Exit 1
24
25cat <<EOF > prog.ok
26msgid "'Your command, please?', asked the waiter."
27msgstr ""
28
29#, python-format
30msgid "%(oldCurrency)s is replaced by %(newCurrency)s."
31msgstr ""
32EOF
33
34: ${DIFF=diff}
35${DIFF} prog.ok prog.pot || Exit 1
36
37cat <<\EOF > fr.po
38msgid ""
39msgstr ""
40"Content-Type: text/plain; charset=ISO-8859-1\n"
41"Plural-Forms: nplurals=2; plural=(n > 1);\n"
42
43msgid "'Your command, please?', asked the waiter."
44msgstr "�Votre commande, s'il vous plait�, dit le gar�on."
45
46# Reverse the arguments.
47#, python-format
48msgid "%(oldCurrency)s is replaced by %(newCurrency)s."
49msgstr "%(newCurrency)s remplace %(oldCurrency)s."
50EOF
51
52: ${MSGMERGE=msgmerge}
53${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || Exit 1
54LC_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
59test -d fr || mkdir fr
60test -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; }
68case `python -c 'import sys; print sys.hexversion >= 0x20000F0'` in
69  1 | True) ;;
70  *) echo "Skipping test: python version too old"; Exit 77;;
71esac
72
73: ${DIFF=diff}
74cat <<\EOF > prog.ok
75Votre commande, s'il vous plait�, dit le gar�on.
76EUR remplace FF.
77EOF
78cat <<\EOF > prog.oku
79«Votre commande, s'il vous plait», dit le garçon.
80EUR remplace FF.
81EOF
82
83: ${LOCALE_FR=fr_FR}
84: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
85if 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
89fi
90if 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
104else
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
113fi
114
115Exit 0
116