Imported Upstream version 0.18.3.2
[platform/upstream/gettext.git] / gettext-tools / tests / lang-php
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
7 tmpfiles=""
8 trap 'rm -fr $tmpfiles' 1 2 3 15
9
10 tmpfiles="$tmpfiles prog.php"
11 cat <<\EOF > prog.php
12 <?php
13   setlocale (LC_ALL, "");
14   textdomain ("prog");
15   bindtextdomain ("prog", "l-php");
16   echo _("'Your command, please?', asked the waiter.");
17   echo "\n";
18   printf(_("%s is replaced by %s."), "FF", "EUR");
19   echo "\n";
20 ?>
21 EOF
22
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; }
29
30 tmpfiles="$tmpfiles l-php-prog.ok"
31 cat <<EOF > l-php-prog.ok
32 msgid "'Your command, please?', asked the waiter."
33 msgstr ""
34
35 #, php-format
36 msgid "%s is replaced by %s."
37 msgstr ""
38 EOF
39
40 : ${DIFF=diff}
41 ${DIFF} l-php-prog.ok l-php-prog.pot || exit 1
42
43 tmpfiles="$tmpfiles l-php-fr.po"
44 cat <<\EOF > l-php-fr.po
45 msgid ""
46 msgstr "Content-Type: text/plain; charset=ISO-8859-1\n"
47
48 msgid "'Your command, please?', asked the waiter."
49 msgstr "«Votre commande, s'il vous plait», dit le garçon."
50
51 # Reverse the arguments.
52 #, php-format
53 msgid "%s is replaced by %s."
54 msgstr "%2$s remplace %1$s."
55 EOF
56
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; }
63
64 : ${DIFF=diff}
65 ${DIFF} l-php-fr.po l-php-fr.po.new || exit 1
66
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
71
72 : ${MSGFMT=msgfmt}
73 ${MSGFMT} -o l-php/fr/LC_MESSAGES/prog.mo l-php-fr.po
74
75 # Test for presence of php version 4.0 or newer with gettext support.
76 (php -v) >/dev/null 2>/dev/null
77 test $? -le 1 \
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
80   [4-9].*) ;;
81   *) echo "Skipping test: php version too old"; rm -fr $tmpfiles; exit 77;;
82 esac
83 { php -m | grep '^gettext$' >/dev/null; } \
84   || { echo "Skipping test: php was built without gettext support"
85        rm -fr $tmpfiles; exit 77
86      }
87
88 # Test which of the fr_FR locales are installed.
89 : ${LOCALE_FR=fr_FR}
90 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
91 if test $LOCALE_FR != none; then
92   LC_ALL=$LOCALE_FR ./testlocale
93   case $? in
94     0) ;;
95     77) LOCALE_FR=none;;
96     *) exit 1;;
97   esac
98 fi
99 if test $LOCALE_FR_UTF8 != none; then
100   LC_ALL=$LOCALE_FR_UTF8 ./testlocale
101   case $? in
102     0) ;;
103     77) LOCALE_FR_UTF8=none;;
104     *) exit 1;;
105   esac
106 fi
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"
110   else
111     echo "Skipping test: no french locale is supported"
112   fi
113   rm -fr $tmpfiles; exit 77
114 fi
115
116 tmpfiles="$tmpfiles l-php-prog.ok l-php-prog.oku l-php-prog.out"
117 : ${DIFF=diff}
118 cat <<\EOF > l-php-prog.ok
119 «Votre commande, s'il vous plait», dit le garçon.
120 EUR remplace FF.
121 EOF
122 cat <<\EOF > l-php-prog.oku
123 «Votre commande, s'il vous plait», dit le garçon.
124 EUR remplace FF.
125 EOF
126
127 : ${LOCALE_FR=fr_FR}
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
132 fi
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
136 fi
137
138 rm -fr $tmpfiles
139
140 exit 0