Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / lang-php
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
8 cat <<\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 ?>
18 EOF
19
20 : ${XGETTEXT=xgettext}
21 ${XGETTEXT} -o prog.tmp --omit-header --no-location prog.php || exit 1
22 LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || exit 1
23
24 cat <<EOF > prog.ok
25 msgid "'Your command, please?', asked the waiter."
26 msgstr ""
27
28 #, php-format
29 msgid "%s is replaced by %s."
30 msgstr ""
31 EOF
32
33 : ${DIFF=diff}
34 ${DIFF} prog.ok prog.pot || exit 1
35
36 cat <<\EOF > fr.po
37 msgid ""
38 msgstr "Content-Type: text/plain; charset=ISO-8859-1\n"
39
40 msgid "'Your command, please?', asked the waiter."
41 msgstr "«Votre commande, s'il vous plait», dit le garçon."
42
43 # Reverse the arguments.
44 #, php-format
45 msgid "%s is replaced by %s."
46 msgstr "%2$s remplace %1$s."
47 EOF
48
49 : ${MSGMERGE=msgmerge}
50 ${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || exit 1
51 LC_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
56 test -d fr || mkdir fr
57 test -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
64 test $? -le 1 \
65   || { echo "Skipping test: php not found"; exit 77; }
66 case `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;;
69 esac
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}
78 if 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
85 fi
86 if 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
93 fi
94 if 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
101 fi
102
103 : ${DIFF=diff}
104 cat <<\EOF > prog.ok
105 «Votre commande, s'il vous plait», dit le garçon.
106 EUR remplace FF.
107 EOF
108 cat <<\EOF > prog.oku
109 «Votre commande, s'il vous plait», dit le garçon.
110 EUR remplace FF.
111 EOF
112
113 : ${LOCALE_FR=fr_FR}
114 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
115 if 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
119 fi
120 if 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
124 fi
125
126 exit 0