No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gettext / gettext-tools / tests / lang-python-2
blob70f889afaacda403abd2436c62d798458d4a7ec6
1 #! /bin/sh
3 # Test of gettext facilities (including plural handling) in the Python
4 # language.
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 LOCALE_FR_UTF8=none
10 tmpfiles=""
11 trap 'rm -fr $tmpfiles' 1 2 3 15
13 tmpfiles="$tmpfiles prog.py"
14 cat <<\EOF > prog.py
15 import sys
16 import gettext
18 n = int(sys.argv[1])
20 gettext.textdomain('prog')
21 gettext.bindtextdomain('prog', '.')
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
30 tmpfiles="$tmpfiles prog.pot"
31 : ${XGETTEXT=xgettext}
32 ${XGETTEXT} -o prog.pot --omit-header --no-location prog.py
34 tmpfiles="$tmpfiles prog.ok"
35 cat <<EOF > prog.ok
36 msgid "'Your command, please?', asked the waiter."
37 msgstr ""
39 #, python-format
40 msgid "a piece of cake"
41 msgid_plural "%(count)d pieces of cake"
42 msgstr[0] ""
43 msgstr[1] ""
45 #, python-format
46 msgid "%(oldCurrency)s is replaced by %(newCurrency)s."
47 msgstr ""
48 EOF
50 : ${DIFF=diff}
51 ${DIFF} prog.ok prog.pot || exit 1
53 tmpfiles="$tmpfiles fr.po"
54 cat <<\EOF > fr.po
55 msgid ""
56 msgstr ""
57 "Content-Type: text/plain; charset=ISO-8859-1\n"
58 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
60 msgid "'Your command, please?', asked the waiter."
61 msgstr "«Votre commande, s'il vous plait», dit le garçon."
63 # Les gateaux allemands sont les meilleurs du monde.
64 #, python-format
65 msgid "a piece of cake"
66 msgid_plural "%(count)d pieces of cake"
67 msgstr[0] "un morceau de gateau"
68 msgstr[1] "%(count)d morceaux de gateau"
70 # Reverse the arguments.
71 #, python-format
72 msgid "%(oldCurrency)s is replaced by %(newCurrency)s."
73 msgstr "%(newCurrency)s remplace %(oldCurrency)s."
74 EOF
76 tmpfiles="$tmpfiles fr.po.new"
77 : ${MSGMERGE=msgmerge}
78 ${MSGMERGE} -q -o fr.po.new fr.po prog.pot
80 : ${DIFF=diff}
81 ${DIFF} fr.po fr.po.new || exit 1
83 tmpfiles="$tmpfiles fr"
84 test -d fr || mkdir fr
85 test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES
87 : ${MSGFMT=msgfmt}
88 ${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po
90 # Test for presence of python version 2.3 or newer.
91 (python -V) >/dev/null 2>/dev/null \
92 || { rm -fr $tmpfiles; exit 77; }
93 case `python -c 'import sys; print sys.hexversion >= 0x20300F0'` in
94 1 | True) ;;
95 *) rm -fr $tmpfiles; exit 77;;
96 esac
98 tmpfiles="$tmpfiles prog.ok prog.oku prog.out"
99 : ${DIFF=diff}
100 cat <<\EOF > prog.ok
101 «Votre commande, s'il vous plait», dit le garçon.
102 2 morceaux de gateau
103 EUR remplace FF.
105 cat <<\EOF > prog.oku
106 «Votre commande, s'il vous plait», dit le garçon.
107 2 morceaux de gateau
108 EUR remplace FF.
111 : ${LOCALE_FR=fr_FR}
112 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
113 if test $LOCALE_FR != none; then
114 LANGUAGE= LC_ALL=$LOCALE_FR python prog.py 2 > prog.out || exit 1
115 ${DIFF} prog.ok prog.out || exit 1
117 if test $LOCALE_FR_UTF8 != none; then
118 LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 python prog.py 2 > prog.out || exit 1
119 ${DIFF} prog.oku prog.out || exit 1
121 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
122 rm -fr $tmpfiles; exit 77
125 rm -fr $tmpfiles
127 exit 0