1#! /bin/sh
2
3# Test of gettext facilities in the guile implementation of Scheme.
4# Assumes an fr_FR locale is installed.
5# Assumes the following packages are installed: guile.
6
7tmpfiles=""
8trap 'rm -fr $tmpfiles' 1 2 3 15
9
10tmpfiles="$tmpfiles prog.scm"
11cat <<\EOF > prog.scm
12(use-modules (ice-9 format))
13
14(setlocale LC_ALL "")
15(textdomain "prog")
16(bindtextdomain "prog" ".")
17
18(define n (string->number (list-ref (command-line) 1)))
19
20(format #t "~A~%" (gettext "'Your command, please?', asked the waiter."))
21
22(format #t "~@?~%" (ngettext "a piece of cake" "~D pieces of cake" n) n)
23
24(format #t "~A~%" (format #f (gettext "~A is replaced by ~A.") "FF" "EUR"))
25EOF
26
27tmpfiles="$tmpfiles prog.tmp prog.pot"
28: ${XGETTEXT=xgettext}
29${XGETTEXT} -o prog.tmp --omit-header --no-location prog.scm
30test $? = 0 || { rm -fr $tmpfiles; exit 1; }
31tr -d '\r' < prog.tmp > prog.pot
32test $? = 0 || { rm -fr $tmpfiles; exit 1; }
33
34tmpfiles="$tmpfiles prog.ok"
35cat <<EOF > prog.ok
36msgid "'Your command, please?', asked the waiter."
37msgstr ""
38
39#, scheme-format
40msgid "a piece of cake"
41msgid_plural "~D pieces of cake"
42msgstr[0] ""
43msgstr[1] ""
44
45#, scheme-format
46msgid "~A is replaced by ~A."
47msgstr ""
48EOF
49
50: ${DIFF=diff}
51${DIFF} prog.ok prog.pot || exit 1
52
53tmpfiles="$tmpfiles fr.po"
54cat <<\EOF > fr.po
55msgid ""
56msgstr ""
57"Content-Type: text/plain; charset=ISO-8859-1\n"
58"Plural-Forms: nplurals=2; plural=(n > 1);\n"
59
60msgid "'Your command, please?', asked the waiter."
61msgstr "�Votre commande, s'il vous plait�, dit le gar�on."
62
63# Les gateaux allemands sont les meilleurs du monde.
64#, scheme-format
65msgid "a piece of cake"
66msgid_plural "~D pieces of cake"
67msgstr[0] "un morceau de gateau"
68msgstr[1] "~D morceaux de gateau"
69
70# Reverse the arguments.
71#, scheme-format
72msgid "~A is replaced by ~A."
73msgstr "~1@*~A remplace ~0@*~A."
74EOF
75
76tmpfiles="$tmpfiles fr.po.tmp fr.po.new"
77: ${MSGMERGE=msgmerge}
78${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot
79test $? = 0 || { rm -fr $tmpfiles; exit 1; }
80tr -d '\r' < fr.po.tmp > fr.po.new
81test $? = 0 || { rm -fr $tmpfiles; exit 1; }
82
83: ${DIFF=diff}
84${DIFF} fr.po fr.po.new || exit 1
85
86tmpfiles="$tmpfiles fr"
87test -d fr || mkdir fr
88test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES
89
90: ${MSGFMT=msgfmt}
91${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po
92
93# Test for presence of guile version 1.7 or newer.
94(guile --version) >/dev/null 2>/dev/null \
95  || { echo "Skipping test: guile not found"; rm -fr $tmpfiles; exit 77; }
96case `guile --version | sed -e 1q | sed -e 's/^[^0-9]*//'` in
97  0.* | 1.[0-6] | 1.[0-6].* )
98    echo "Skipping test: guile version too old"; rm -fr $tmpfiles; exit 77;;
99esac
100
101# Test which of the fr_FR locales are installed.
102: ${LOCALE_FR=fr_FR}
103: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
104if test $LOCALE_FR != none; then
105  LC_ALL=$LOCALE_FR ./testlocale
106  case $? in
107    0) ;;
108    77) LOCALE_FR=none;;
109    *) exit 1;;
110  esac
111fi
112if test $LOCALE_FR_UTF8 != none; then
113  LC_ALL=$LOCALE_FR_UTF8 ./testlocale
114  case $? in
115    0) ;;
116    77) LOCALE_FR_UTF8=none;;
117    *) exit 1;;
118  esac
119fi
120if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
121  if test -f /usr/bin/localedef; then
122    echo "Skipping test: no french locale is installed"
123  else
124    echo "Skipping test: no french locale is supported"
125  fi
126  rm -fr $tmpfiles; exit 77
127fi
128
129tmpfiles="$tmpfiles prog.ok prog.oku prog.out"
130: ${DIFF=diff}
131cat <<\EOF > prog.ok
132Votre commande, s'il vous plait�, dit le gar�on.
1332 morceaux de gateau
134EUR remplace FF.
135EOF
136cat <<\EOF > prog.oku
137��Votre commande, s'il vous plait��, dit le gar��on.
1382 morceaux de gateau
139EUR remplace FF.
140EOF
141
142: ${LOCALE_FR=fr_FR}
143: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
144if test $LOCALE_FR != none; then
145  LANGUAGE= LC_ALL=$LOCALE_FR guile -s prog.scm 2 > prog.out || exit 1
146  ${DIFF} prog.ok prog.out || exit 1
147fi
148if test $LOCALE_FR_UTF8 != none; then
149  LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 guile -s prog.scm 2 > prog.out || exit 1
150  ${DIFF} prog.oku prog.out || exit 1
151fi
152
153rm -fr $tmpfiles
154
155exit 0
156