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