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