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