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