lang-gawk revision 1.1 1 1.1 christos #! /bin/sh
2 1.1 christos
3 1.1 christos # Test of gettext facilities in the GNU awk language.
4 1.1 christos # Assumes an fr_FR locale is installed.
5 1.1 christos # Assumes the following packages are installed: gawk.
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 prog.awk"
15 1.1 christos cat <<\EOF > prog.awk
16 1.1 christos BEGIN {
17 1.1 christos TEXTDOMAIN = "prog"
18 1.1 christos bindtextdomain ("./")
19 1.1 christos
20 1.1 christos print _"'Your command, please?', asked the waiter."
21 1.1 christos
22 1.1 christos printf dcngettext ("a piece of cake", "%d pieces of cake", n) "\n", n
23 1.1 christos
24 1.1 christos printf _"%s is replaced by %s." "\n", "FF", "EUR"
25 1.1 christos }
26 1.1 christos EOF
27 1.1 christos
28 1.1 christos tmpfiles="$tmpfiles prog.pot"
29 1.1 christos : ${XGETTEXT=xgettext}
30 1.1 christos ${XGETTEXT} -o prog.pot --omit-header --no-location prog.awk
31 1.1 christos
32 1.1 christos tmpfiles="$tmpfiles prog.ok"
33 1.1 christos cat <<EOF > prog.ok
34 1.1 christos msgid "'Your command, please?', asked the waiter."
35 1.1 christos msgstr ""
36 1.1 christos
37 1.1 christos #, awk-format
38 1.1 christos msgid "a piece of cake"
39 1.1 christos msgid_plural "%d pieces of cake"
40 1.1 christos msgstr[0] ""
41 1.1 christos msgstr[1] ""
42 1.1 christos
43 1.1 christos #, awk-format
44 1.1 christos msgid "%s is replaced by %s."
45 1.1 christos msgstr ""
46 1.1 christos EOF
47 1.1 christos
48 1.1 christos : ${DIFF=diff}
49 1.1 christos ${DIFF} prog.ok prog.pot || exit 1
50 1.1 christos
51 1.1 christos tmpfiles="$tmpfiles fr.po"
52 1.1 christos cat <<\EOF > fr.po
53 1.1 christos msgid ""
54 1.1 christos msgstr ""
55 1.1 christos "Content-Type: text/plain; charset=ISO-8859-1\n"
56 1.1 christos "Plural-Forms: nplurals=2; plural=(n > 1);\n"
57 1.1 christos
58 1.1 christos msgid "'Your command, please?', asked the waiter."
59 1.1 christos msgstr "Votre commande, s'il vous plait, dit le garon."
60 1.1 christos
61 1.1 christos # Les gateaux allemands sont les meilleurs du monde.
62 1.1 christos #, awk-format
63 1.1 christos msgid "a piece of cake"
64 1.1 christos msgid_plural "%d pieces of cake"
65 1.1 christos msgstr[0] "un morceau de gateau"
66 1.1 christos msgstr[1] "%d morceaux de gateau"
67 1.1 christos
68 1.1 christos # Reverse the arguments.
69 1.1 christos #, awk-format
70 1.1 christos msgid "%s is replaced by %s."
71 1.1 christos msgstr "%2$s remplace %1$s."
72 1.1 christos EOF
73 1.1 christos
74 1.1 christos tmpfiles="$tmpfiles fr.po.new"
75 1.1 christos : ${MSGMERGE=msgmerge}
76 1.1 christos ${MSGMERGE} -q -o fr.po.new fr.po prog.pot
77 1.1 christos
78 1.1 christos : ${DIFF=diff}
79 1.1 christos ${DIFF} fr.po fr.po.new || exit 1
80 1.1 christos
81 1.1 christos tmpfiles="$tmpfiles fr"
82 1.1 christos test -d fr || mkdir fr
83 1.1 christos test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES
84 1.1 christos
85 1.1 christos : ${MSGFMT=msgfmt}
86 1.1 christos ${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po
87 1.1 christos
88 1.1 christos # Test for presence of gawk version 3.1.3 or newer.
89 1.1 christos (gawk --version) >/dev/null 2>/dev/null \
90 1.1 christos || { echo "Skipping test: gawk not found"; rm -fr $tmpfiles; exit 77; }
91 1.1 christos case `gawk --version 2>&1 | sed -e 's/^[^0-9]*//'` in
92 1.1 christos 0.* | 1.* | 2.* | 3.0* | 3.1.0* | 3.1.1* | 3.1.2*)
93 1.1 christos echo "Skipping test: gawk version too old"; rm -fr $tmpfiles; exit 77;;
94 1.1 christos esac
95 1.1 christos
96 1.1 christos # Test which of the fr_FR locales are installed.
97 1.1 christos : ${LOCALE_FR=fr_FR}
98 1.1 christos : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
99 1.1 christos if test $LOCALE_FR != none; then
100 1.1 christos LC_ALL=$LOCALE_FR ./testlocale
101 1.1 christos case $? in
102 1.1 christos 0) ;;
103 1.1 christos 77) LOCALE_FR=none;;
104 1.1 christos *) exit 1;;
105 1.1 christos esac
106 1.1 christos fi
107 1.1 christos if test $LOCALE_FR_UTF8 != none; then
108 1.1 christos LC_ALL=$LOCALE_FR_UTF8 ./testlocale
109 1.1 christos case $? in
110 1.1 christos 0) ;;
111 1.1 christos 77) LOCALE_FR_UTF8=none;;
112 1.1 christos *) exit 1;;
113 1.1 christos esac
114 1.1 christos fi
115 1.1 christos if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
116 1.1 christos if test -f /usr/bin/localedef; then
117 1.1 christos echo "Skipping test: no french locale is installed"
118 1.1 christos else
119 1.1 christos echo "Skipping test: no french locale is supported"
120 1.1 christos fi
121 1.1 christos rm -fr $tmpfiles; exit 77
122 1.1 christos fi
123 1.1 christos
124 1.1 christos # Test that gawk wasn't built with --disable-nls.
125 1.1 christos : ${LOCALE_FR=fr_FR}
126 1.1 christos : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
127 1.1 christos if test $LOCALE_FR != none; then
128 1.1 christos LANGUAGE= LC_ALL=$LOCALE_FR gawk --version | grep logiciel > /dev/null
129 1.1 christos test $? = 0 || {
130 1.1 christos echo "Skipping test: gawk was built without i18n support"
131 1.1 christos rm -fr $tmpfiles; exit 77
132 1.1 christos }
133 1.1 christos fi
134 1.1 christos if test $LOCALE_FR_UTF8 != none; then
135 1.1 christos LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 gawk --version | grep logiciel > /dev/null
136 1.1 christos test $? = 0 || {
137 1.1 christos echo "Skipping test: gawk was built without i18n support"
138 1.1 christos rm -fr $tmpfiles; exit 77
139 1.1 christos }
140 1.1 christos fi
141 1.1 christos
142 1.1 christos tmpfiles="$tmpfiles prog.ok prog.oku prog.out"
143 1.1 christos : ${DIFF=diff}
144 1.1 christos cat <<\EOF > prog.ok
145 1.1 christos Votre commande, s'il vous plait, dit le garon.
146 1.1 christos 2 morceaux de gateau
147 1.1 christos EUR remplace FF.
148 1.1 christos EOF
149 1.1 christos cat <<\EOF > prog.oku
150 1.1 christos Votre commande, s'il vous plait, dit le garon.
151 1.1 christos 2 morceaux de gateau
152 1.1 christos EUR remplace FF.
153 1.1 christos EOF
154 1.1 christos
155 1.1 christos : ${LOCALE_FR=fr_FR}
156 1.1 christos : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
157 1.1 christos if test $LOCALE_FR != none; then
158 1.1 christos LANGUAGE= LC_ALL=$LOCALE_FR gawk -v n=2 -f prog.awk > prog.out || exit 1
159 1.1 christos ${DIFF} prog.ok prog.out || exit 1
160 1.1 christos fi
161 1.1 christos if test $LOCALE_FR_UTF8 != none; then
162 1.1 christos LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 gawk -v n=2 -f prog.awk > prog.out || exit 1
163 1.1 christos ${DIFF} prog.oku prog.out || exit 1
164 1.1 christos fi
165 1.1 christos
166 1.1 christos rm -fr $tmpfiles
167 1.1 christos
168 1.1 christos exit 0
169