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