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