xref: /netbsd-src/external/gpl2/gettext/dist/gettext-tools/tests/lang-tcl (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
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
11tmpfiles=""
12trap 'rm -fr $tmpfiles' 1 2 3 15
13
14tmpfiles="$tmpfiles program.tcl"
15cat <<\EOF > program.tcl
16#!/usr/bin/env tclsh
17package require msgcat
18::msgcat::mcload [file join [file dirname [info script]] msgs]
19proc _ {s} {return [::msgcat::mc $s]}
20puts [_ "'Your command, please?', asked the waiter."]
21puts [format [::msgcat::mc "%s is replaced by %s."] "FF" "EUR"]
22EOF
23
24tmpfiles="$tmpfiles prog.pot"
25: ${XGETTEXT=xgettext}
26${XGETTEXT} -o prog.pot --omit-header -k_ program.tcl
27
28tmpfiles="$tmpfiles prog.ok"
29cat <<EOF > prog.ok
30#: program.tcl:5
31msgid "'Your command, please?', asked the waiter."
32msgstr ""
33
34#: program.tcl:6
35#, tcl-format
36msgid "%s is replaced by %s."
37msgstr ""
38EOF
39
40: ${DIFF=diff}
41${DIFF} prog.ok prog.pot || exit 1
42
43tmpfiles="$tmpfiles fr.po"
44cat <<\EOF > fr.po
45msgid ""
46msgstr "Content-Type: text/plain; charset=ISO-8859-1\n"
47
48#: program.tcl:5
49msgid "'Your command, please?', asked the waiter."
50msgstr "�Votre commande, s'il vous plait�, dit le gar�on."
51
52# Reverse the arguments.
53#: program.tcl:6
54#, tcl-format
55msgid "%s is replaced by %s."
56msgstr "%2$s remplace %1$s."
57EOF
58
59tmpfiles="$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
66tmpfiles="$tmpfiles msgs"
67test -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.
73tmpfiles="$tmpfiles version.tcl"
74cat <<\EOF > version.tcl
75package require msgcat
76puts $tcl_version
77EOF
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
83tmpfiles="$tmpfiles prog.ok prog.oku prog.out"
84: ${DIFF=diff}
85cat <<\EOF > prog.ok
86Votre commande, s'il vous plait�, dit le gar�on.
87EUR remplace FF.
88EOF
89cat <<\EOF > prog.oku
90«Votre commande, s'il vous plait», dit le garçon.
91EUR remplace FF.
92EOF
93
94: ${LOCALE_FR=fr_FR}
95: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
96if 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
99fi
100if 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
103fi
104if 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
111fi
112
113rm -fr $tmpfiles
114
115exit 0
116