1233294Sstas#! /bin/sh 2178825Sdfr 3178825Sdfr# Test of gettext facilities in the Python language. 4178825Sdfr 5178825Sdfr# Note: This test fails with Python 2.3, 2.4 when an UTF-8 locale is present. 6178825Sdfr# It looks like a bug in Python's gettext.py. This here is a quick workaround: 7178825SdfrUTF8_LOCALE_UNSUPPORTED=yes 8178825Sdfr 9178825Sdfrtmpfiles="" 10233294Sstastrap 'rm -fr $tmpfiles' 1 2 3 15 11178825Sdfr 12178825Sdfrtmpfiles="$tmpfiles prog.py" 13178825Sdfrcat <<\EOF > prog.py 14178825Sdfrimport gettext 15178825Sdfr 16178825Sdfrgettext.textdomain('prog') 17178825Sdfrgettext.bindtextdomain('prog', '.') 18178825Sdfr 19178825Sdfrprint gettext.gettext("'Your command, please?', asked the waiter.") 20178825Sdfrprint gettext.gettext("%(oldCurrency)s is replaced by %(newCurrency)s.") \ 21178825Sdfr % { 'oldCurrency': "FF", 'newCurrency' : "EUR" } 22178825SdfrEOF 23178825Sdfr 24178825Sdfrtmpfiles="$tmpfiles prog.pot" 25178825Sdfr: ${XGETTEXT=xgettext} 26178825Sdfr${XGETTEXT} -o prog.pot --omit-header --no-location prog.py 27178825Sdfr 28178825Sdfrtmpfiles="$tmpfiles prog.ok" 29178825Sdfrcat <<EOF > prog.ok 30178825Sdfrmsgid "'Your command, please?', asked the waiter." 31178825Sdfrmsgstr "" 32178825Sdfr 33178825Sdfr#, python-format 34178825Sdfrmsgid "%(oldCurrency)s is replaced by %(newCurrency)s." 35msgstr "" 36EOF 37 38: ${DIFF=diff} 39${DIFF} prog.ok prog.pot || exit 1 40 41tmpfiles="$tmpfiles fr.po" 42cat <<\EOF > fr.po 43msgid "" 44msgstr "" 45"Content-Type: text/plain; charset=ISO-8859-1\n" 46"Plural-Forms: nplurals=2; plural=(n > 1);\n" 47 48msgid "'Your command, please?', asked the waiter." 49msgstr "�Votre commande, s'il vous plait�, dit le gar�on." 50 51# Reverse the arguments. 52#, python-format 53msgid "%(oldCurrency)s is replaced by %(newCurrency)s." 54msgstr "%(newCurrency)s remplace %(oldCurrency)s." 55EOF 56 57tmpfiles="$tmpfiles fr.po.new" 58: ${MSGMERGE=msgmerge} 59${MSGMERGE} -q -o fr.po.new fr.po prog.pot 60 61: ${DIFF=diff} 62${DIFF} fr.po fr.po.new || exit 1 63 64tmpfiles="$tmpfiles fr" 65test -d fr || mkdir fr 66test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES 67 68: ${MSGFMT=msgfmt} 69${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po 70 71# Test for presence of python version 2.0 or newer. 72(python -V) >/dev/null 2>/dev/null \ 73 || { echo "Skipping test: python not found"; rm -fr $tmpfiles; exit 77; } 74case `python -c 'import sys; print sys.hexversion >= 0x20000F0'` in 75 1 | True) ;; 76 *) echo "Skipping test: python version too old"; rm -fr $tmpfiles; exit 77;; 77esac 78 79tmpfiles="$tmpfiles prog.ok prog.oku prog.out" 80: ${DIFF=diff} 81cat <<\EOF > prog.ok 82�Votre commande, s'il vous plait�, dit le gar�on. 83EUR remplace FF. 84EOF 85cat <<\EOF > prog.oku 86��Votre commande, s'il vous plait��, dit le gar��on. 87EUR remplace FF. 88EOF 89 90: ${LOCALE_FR=fr_FR} 91: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 92if test $LOCALE_FR != none; then 93 LANGUAGE= LC_ALL=$LOCALE_FR python prog.py > prog.out || exit 1 94 ${DIFF} prog.ok prog.out || exit 1 95fi 96if test -z "$UTF8_LOCALE_UNSUPPORTED"; then 97 if test $LOCALE_FR_UTF8 != none; then 98 LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 python prog.py > prog.out || exit 1 99 ${DIFF} prog.oku prog.out || exit 1 100 fi 101 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then 102 if test -f /usr/bin/localedef; then 103 echo "Skipping test: no french locale is installed" 104 else 105 echo "Skipping test: no french locale is supported" 106 fi 107 rm -fr $tmpfiles; exit 77 108 fi 109else 110 if test $LOCALE_FR = none; then 111 if test -f /usr/bin/localedef; then 112 echo "Skipping test: no traditional french locale is installed" 113 else 114 echo "Skipping test: no traditional french locale is supported" 115 fi 116 rm -fr $tmpfiles; exit 77 117 fi 118fi 119 120rm -fr $tmpfiles 121 122exit 0 123