3 # Test of gettext facilities in the PHP language.
4 # Assumes an fr_FR locale is installed.
5 # Assumes the following packages are installed: mod_php4-core.
8 trap 'rm -fr $tmpfiles' 1 2 3 15
10 tmpfiles="$tmpfiles prog.php"
13 setlocale (LC_ALL, "");
15 bindtextdomain ("prog", "l-php");
16 echo _("'Your command, please?', asked the waiter.");
18 printf(_("%s is replaced by %s."), "FF", "EUR");
23 tmpfiles="$tmpfiles l-php-prog.tmp l-php-prog.pot"
24 : ${XGETTEXT=xgettext}
25 ${XGETTEXT} -o l-php-prog.tmp --omit-header --no-location prog.php
26 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
27 LC_ALL=C tr -d '\r' < l-php-prog.tmp > l-php-prog.pot
28 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
30 tmpfiles="$tmpfiles l-php-prog.ok"
31 cat <<EOF > l-php-prog.ok
32 msgid "'Your command, please?', asked the waiter."
36 msgid "%s is replaced by %s."
41 ${DIFF} l-php-prog.ok l-php-prog.pot || exit 1
43 tmpfiles="$tmpfiles l-php-fr.po"
44 cat <<\EOF > l-php-fr.po
46 msgstr "Content-Type: text/plain; charset=ISO-8859-1\n"
48 msgid "'Your command, please?', asked the waiter."
49 msgstr "«Votre commande, s'il vous plait», dit le garçon."
51 # Reverse the arguments.
53 msgid "%s is replaced by %s."
54 msgstr "%2$s remplace %1$s."
57 tmpfiles="$tmpfiles l-php-fr.po.tmp l-php-fr.po.new"
58 : ${MSGMERGE=msgmerge}
59 ${MSGMERGE} -q -o l-php-fr.po.tmp l-php-fr.po l-php-prog.pot
60 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
61 LC_ALL=C tr -d '\r' < l-php-fr.po.tmp > l-php-fr.po.new
62 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
65 ${DIFF} l-php-fr.po l-php-fr.po.new || exit 1
67 tmpfiles="$tmpfiles l-php"
68 test -d l-php || mkdir l-php
69 test -d l-php/fr || mkdir l-php/fr
70 test -d l-php/fr/LC_MESSAGES || mkdir l-php/fr/LC_MESSAGES
73 ${MSGFMT} -o l-php/fr/LC_MESSAGES/prog.mo l-php-fr.po
75 # Test for presence of php version 4.0 or newer with gettext support.
76 (php -v) >/dev/null 2>/dev/null
78 || { echo "Skipping test: php not found"; rm -fr $tmpfiles; exit 77; }
79 case `php -v | sed -n -e 1p | sed -e 's/^[^0-9]*//'` in
81 *) echo "Skipping test: php version too old"; rm -fr $tmpfiles; exit 77;;
83 { php -m | grep '^gettext$' >/dev/null; } \
84 || { echo "Skipping test: php was built without gettext support"
85 rm -fr $tmpfiles; exit 77
88 # Test which of the fr_FR locales are installed.
90 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
91 if test $LOCALE_FR != none; then
92 LC_ALL=$LOCALE_FR ./testlocale
99 if test $LOCALE_FR_UTF8 != none; then
100 LC_ALL=$LOCALE_FR_UTF8 ./testlocale
103 77) LOCALE_FR_UTF8=none;;
107 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
108 if test -f /usr/bin/localedef; then
109 echo "Skipping test: no french locale is installed"
111 echo "Skipping test: no french locale is supported"
113 rm -fr $tmpfiles; exit 77
116 tmpfiles="$tmpfiles l-php-prog.ok l-php-prog.oku l-php-prog.out"
118 cat <<\EOF > l-php-prog.ok
119 «Votre commande, s'il vous plait», dit le garçon.
122 cat <<\EOF > l-php-prog.oku
123 «Votre commande, s'il vous plait», dit le garçon.
128 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
129 if test $LOCALE_FR != none; then
130 LANGUAGE= LC_ALL=$LOCALE_FR php -q prog.php > l-php-prog.out || exit 1
131 ${DIFF} l-php-prog.ok l-php-prog.out || exit 1
133 if test $LOCALE_FR_UTF8 != none; then
134 LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 php -q prog.php > l-php-prog.out || exit 1
135 ${DIFF} l-php-prog.oku l-php-prog.out || exit 1