1#! /bin/sh 2. "${srcdir=.}/init.sh"; path_prepend_ . ../src 3 4# Test of gettext facilities in the PHP language. 5# Assumes an fr_FR locale is installed. 6# Assumes the following packages are installed: mod_php4-core. 7 8cat <<\EOF > prog.php 9<?php 10 setlocale (LC_ALL, ""); 11 textdomain ("prog"); 12 bindtextdomain ("prog", "."); 13 echo _("'Your command, please?', asked the waiter."); 14 echo "\n"; 15 printf(_("%s is replaced by %s."), "FF", "EUR"); 16 echo "\n"; 17?> 18EOF 19 20: ${XGETTEXT=xgettext} 21${XGETTEXT} -o prog.tmp --omit-header --no-location prog.php || Exit 1 22LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || Exit 1 23 24cat <<EOF > prog.ok 25msgid "'Your command, please?', asked the waiter." 26msgstr "" 27 28#, php-format 29msgid "%s is replaced by %s." 30msgstr "" 31EOF 32 33: ${DIFF=diff} 34${DIFF} prog.ok prog.pot || Exit 1 35 36cat <<\EOF > fr.po 37msgid "" 38msgstr "Content-Type: text/plain; charset=ISO-8859-1\n" 39 40msgid "'Your command, please?', asked the waiter." 41msgstr "�Votre commande, s'il vous plait�, dit le gar�on." 42 43# Reverse the arguments. 44#, php-format 45msgid "%s is replaced by %s." 46msgstr "%2$s remplace %1$s." 47EOF 48 49: ${MSGMERGE=msgmerge} 50${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || Exit 1 51LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new || Exit 1 52 53: ${DIFF=diff} 54${DIFF} fr.po fr.po.new || Exit 1 55 56test -d fr || mkdir fr 57test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES 58 59: ${MSGFMT=msgfmt} 60${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po 61 62# Test for presence of php version 4.0 or newer with gettext support. 63(php -v) >/dev/null 2>/dev/null 64test $? -le 1 \ 65 || { echo "Skipping test: php not found"; Exit 77; } 66case `php -v | sed -n -e 1p | sed -e 's/^[^0-9]*//'` in 67 [4-9].*) ;; 68 *) echo "Skipping test: php version too old"; Exit 77;; 69esac 70{ php -m | grep '^gettext$' >/dev/null; } \ 71 || { echo "Skipping test: php was built without gettext support" 72 Exit 77 73 } 74 75# Test which of the fr_FR locales are installed. 76: ${LOCALE_FR=fr_FR} 77: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 78if test $LOCALE_FR != none; then 79 LC_ALL=$LOCALE_FR ../testlocale 80 case $? in 81 0) ;; 82 77) LOCALE_FR=none;; 83 *) Exit 1;; 84 esac 85fi 86if test $LOCALE_FR_UTF8 != none; then 87 LC_ALL=$LOCALE_FR_UTF8 ../testlocale 88 case $? in 89 0) ;; 90 77) LOCALE_FR_UTF8=none;; 91 *) Exit 1;; 92 esac 93fi 94if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then 95 if test -f /usr/bin/localedef; then 96 echo "Skipping test: no french locale is installed" 97 else 98 echo "Skipping test: no french locale is supported" 99 fi 100 Exit 77 101fi 102 103: ${DIFF=diff} 104cat <<\EOF > prog.ok 105�Votre commande, s'il vous plait�, dit le gar�on. 106EUR remplace FF. 107EOF 108cat <<\EOF > prog.oku 109«Votre commande, s'il vous plait», dit le garçon. 110EUR remplace FF. 111EOF 112 113: ${LOCALE_FR=fr_FR} 114: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 115if test $LOCALE_FR != none; then 116 prepare_locale_ fr $LOCALE_FR 117 LANGUAGE= LC_ALL=$LOCALE_FR php -q prog.php > prog.out || Exit 1 118 ${DIFF} prog.ok prog.out || Exit 1 119fi 120if test $LOCALE_FR_UTF8 != none; then 121 prepare_locale_ fr $LOCALE_FR_UTF8 122 LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 php -q prog.php > prog.out || Exit 1 123 ${DIFF} prog.oku prog.out || Exit 1 124fi 125 126Exit 0 127