Home | History | Annotate | Line # | Download | only in tests
      1  1.1  christos #! /bin/sh
      2  1.1  christos 
      3  1.1  christos # Test of gettext facilities in the Tcl language.
      4  1.1  christos # Assumes an fr_FR locale is installed.
      5  1.1  christos # Assumes the following packages are installed: tcl.
      6  1.1  christos 
      7  1.1  christos # Note: This test fails on MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale
      8  1.1  christos # but not in the fr_FR.UTF-8 locale. Probably because in the fr_FR locale,
      9  1.1  christos # nl_langinfo(CODESET) returns "".
     10  1.1  christos 
     11  1.1  christos tmpfiles=""
     12  1.1  christos trap 'rm -fr $tmpfiles' 1 2 3 15
     13  1.1  christos 
     14  1.1  christos tmpfiles="$tmpfiles program.tcl"
     15  1.1  christos cat <<\EOF > program.tcl
     16  1.1  christos #!/usr/bin/env tclsh
     17  1.1  christos package require msgcat
     18  1.1  christos ::msgcat::mcload [file join [file dirname [info script]] msgs]
     19  1.1  christos proc _ {s} {return [::msgcat::mc $s]}
     20  1.1  christos puts [_ "'Your command, please?', asked the waiter."]
     21  1.1  christos puts [format [::msgcat::mc "%s is replaced by %s."] "FF" "EUR"]
     22  1.1  christos EOF
     23  1.1  christos 
     24  1.1  christos tmpfiles="$tmpfiles prog.pot"
     25  1.1  christos : ${XGETTEXT=xgettext}
     26  1.1  christos ${XGETTEXT} -o prog.pot --omit-header -k_ program.tcl
     27  1.1  christos 
     28  1.1  christos tmpfiles="$tmpfiles prog.ok"
     29  1.1  christos cat <<EOF > prog.ok
     30  1.1  christos #: program.tcl:5
     31  1.1  christos msgid "'Your command, please?', asked the waiter."
     32  1.1  christos msgstr ""
     33  1.1  christos 
     34  1.1  christos #: program.tcl:6
     35  1.1  christos #, tcl-format
     36  1.1  christos msgid "%s is replaced by %s."
     37  1.1  christos msgstr ""
     38  1.1  christos EOF
     39  1.1  christos 
     40  1.1  christos : ${DIFF=diff}
     41  1.1  christos ${DIFF} prog.ok prog.pot || exit 1
     42  1.1  christos 
     43  1.1  christos tmpfiles="$tmpfiles fr.po"
     44  1.1  christos cat <<\EOF > fr.po
     45  1.1  christos msgid ""
     46  1.1  christos msgstr "Content-Type: text/plain; charset=ISO-8859-1\n"
     47  1.1  christos 
     48  1.1  christos #: program.tcl:5
     49  1.1  christos msgid "'Your command, please?', asked the waiter."
     50  1.1  christos msgstr "Votre commande, s'il vous plait, dit le garon."
     51  1.1  christos 
     52  1.1  christos # Reverse the arguments.
     53  1.1  christos #: program.tcl:6
     54  1.1  christos #, tcl-format
     55  1.1  christos msgid "%s is replaced by %s."
     56  1.1  christos msgstr "%2$s remplace %1$s."
     57  1.1  christos EOF
     58  1.1  christos 
     59  1.1  christos tmpfiles="$tmpfiles fr.po.new"
     60  1.1  christos : ${MSGMERGE=msgmerge}
     61  1.1  christos ${MSGMERGE} -q -o fr.po.new fr.po prog.pot
     62  1.1  christos 
     63  1.1  christos : ${DIFF=diff}
     64  1.1  christos ${DIFF} fr.po fr.po.new || exit 1
     65  1.1  christos 
     66  1.1  christos tmpfiles="$tmpfiles msgs"
     67  1.1  christos test -d msgs || mkdir msgs
     68  1.1  christos 
     69  1.1  christos : ${MSGFMT=msgfmt}
     70  1.1  christos ${MSGFMT} --tcl -d msgs -l fr fr.po || exit 1
     71  1.1  christos 
     72  1.1  christos # Test for presence of tclsh with msgcat extension.
     73  1.1  christos tmpfiles="$tmpfiles version.tcl"
     74  1.1  christos cat <<\EOF > version.tcl
     75  1.1  christos package require msgcat
     76  1.1  christos puts $tcl_version
     77  1.1  christos EOF
     78  1.1  christos (tclsh version.tcl) >/dev/null 2>/dev/null \
     79  1.1  christos   || { echo "Skipping test: tclsh not found or msgcat extension not present"
     80  1.1  christos        rm -fr $tmpfiles; exit 77
     81  1.1  christos      }
     82  1.1  christos 
     83  1.1  christos tmpfiles="$tmpfiles prog.ok prog.oku prog.out"
     84  1.1  christos : ${DIFF=diff}
     85  1.1  christos cat <<\EOF > prog.ok
     86  1.1  christos Votre commande, s'il vous plait, dit le garon.
     87  1.1  christos EUR remplace FF.
     88  1.1  christos EOF
     89  1.1  christos cat <<\EOF > prog.oku
     90  1.1  christos Votre commande, s'il vous plait, dit le garon.
     91  1.1  christos EUR remplace FF.
     92  1.1  christos EOF
     93  1.1  christos 
     94  1.1  christos : ${LOCALE_FR=fr_FR}
     95  1.1  christos : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
     96  1.1  christos if test $LOCALE_FR != none; then
     97  1.1  christos   LANGUAGE= LANG=$LOCALE_FR LC_MESSAGES= LC_CTYPE= LC_ALL= tclsh program.tcl > prog.out || exit 1
     98  1.1  christos   ${DIFF} prog.ok prog.out || exit 1
     99  1.1  christos fi
    100  1.1  christos if test $LOCALE_FR_UTF8 != none; then
    101  1.1  christos   LANGUAGE= LANG=$LOCALE_FR_UTF8 LC_MESSAGES= LC_CTYPE= LC_ALL= tclsh program.tcl > prog.out || exit 1
    102  1.1  christos   ${DIFF} prog.oku prog.out || exit 1
    103  1.1  christos fi
    104  1.1  christos if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
    105  1.1  christos   if test -f /usr/bin/localedef; then
    106  1.1  christos     echo "Skipping test: no french locale is installed"
    107  1.1  christos   else
    108  1.1  christos     echo "Skipping test: no french locale is supported"
    109  1.1  christos   fi
    110  1.1  christos   rm -fr $tmpfiles; exit 77
    111  1.1  christos fi
    112  1.1  christos 
    113  1.1  christos rm -fr $tmpfiles
    114  1.1  christos 
    115  1.1  christos exit 0
    116