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