Imported Upstream version 0.18.3.2
[platform/upstream/gettext.git] / gettext-tools / tests / lang-java
1 #! /bin/sh
2
3 # Test of gettext facilities in the Java language.
4 # Assumes an fr_FR locale is installed.
5 # Assumes the following packages are installed: java.
6
7 # Note: This test fails when using gcj from GCC 3.1 and GCC 3.2, due to a bug
8 # (libgcj/6576). It is fixed in GCC 3.3.
9
10 tmpfiles=""
11 trap 'rm -fr $tmpfiles' 1 2 3 15
12
13 # Test whether we can build and test Java programs.
14 test "${JAVA_CHOICE}" != no || {
15   echo "Skipping test: configured with --disable-java"
16   exit 77
17 }
18 test "${BUILDJAVA}" = yes || {
19   echo "Skipping test: Java compiler or jar not found"
20   exit 77
21 }
22 test "${TESTJAVA}" = yes || {
23   echo "Skipping test: Java engine not found"
24   exit 77
25 }
26
27 tmpfiles="$tmpfiles Program.java"
28 cat <<\EOF > Program.java
29 import java.util.*;
30 import java.io.*;
31 import java.text.*;
32 import gnu.gettext.*;
33
34 public class Program {
35   public static void main (String[] args) {
36     // Some systems (like Solaris) don't set Locale.getDefault()
37     // as specified by LC_ALL. So set it by hand.
38     Locale.setDefault(new Locale("fr","FR"));
39 EOF
40 case "$host_os" in
41   darwin*)
42 cat <<\EOF >> Program.java
43     // Some systems (like MacOS X) don't set System.out's character encoding
44     // according to LC_ALL, which is what we need for comparison purposes.
45     try {
46       System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out),
47                                     true, args[1]));
48     } catch (UnsupportedEncodingException e) {
49     }
50 EOF
51     ;;
52 esac
53 cat <<\EOF >> Program.java
54     int n = Integer.parseInt(args[0]);
55     ResourceBundle catalog = ResourceBundle.getBundle("prog");
56     System.out.println(GettextResource.gettext(catalog,"'Your command, please?', asked the waiter."));
57     System.out.println(MessageFormat.format(GettextResource.ngettext(catalog,"a piece of cake","{0,number} pieces of cake",n), new Object[] { new Integer(n) }));
58     System.out.println(MessageFormat.format(GettextResource.gettext(catalog,"{0} is replaced by {1}."), new Object[] { "FF", "EUR" }));
59     System.out.println(MessageFormat.format(GettextResource.npgettext(catalog,"++","a piece of cake","{0,number} pieces of cake",n), new Object[] { new Integer(n) }));
60     System.out.println(MessageFormat.format(GettextResource.pgettext(catalog,"++","{0} is replaced by {1}."), new Object[] { "FF", "EUR" }));
61   }
62 }
63 EOF
64
65 tmpfiles="$tmpfiles Program.class l-java l-java-prog.err"
66 test -d l-java || mkdir l-java
67
68 : ${JAVACOMP="/bin/sh ../javacomp.sh"}
69 CLASSPATH=../../gettext-runtime/intl-java/libintl.jar ${JAVACOMP} -d l-java Program.java 2>l-java-prog.err \
70   || { cat l-java-prog.err 1>&2; exit 1; }
71
72 tmpfiles="$tmpfiles l-java-prog.tmp l-java-prog.pot"
73 : ${XGETTEXT=xgettext}
74 ${XGETTEXT} -o l-java-prog.tmp --omit-header --no-location Program.java
75 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
76 LC_ALL=C tr -d '\r' < l-java-prog.tmp > l-java-prog.pot
77 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
78
79 tmpfiles="$tmpfiles l-java-prog.ok"
80 cat <<EOF > l-java-prog.ok
81 msgid "'Your command, please?', asked the waiter."
82 msgstr ""
83
84 #, java-format
85 msgid "a piece of cake"
86 msgid_plural "{0,number} pieces of cake"
87 msgstr[0] ""
88 msgstr[1] ""
89
90 #, java-format
91 msgid "{0} is replaced by {1}."
92 msgstr ""
93
94 #, java-format
95 msgctxt "++"
96 msgid "a piece of cake"
97 msgid_plural "{0,number} pieces of cake"
98 msgstr[0] ""
99 msgstr[1] ""
100
101 #, java-format
102 msgctxt "++"
103 msgid "{0} is replaced by {1}."
104 msgstr ""
105 EOF
106
107 : ${DIFF=diff}
108 ${DIFF} l-java-prog.ok l-java-prog.pot || exit 1
109
110 tmpfiles="$tmpfiles l-java-fr.po"
111 cat <<\EOF > l-java-fr.po
112 msgid ""
113 msgstr ""
114 "Content-Type: text/plain; charset=ISO-8859-1\n"
115 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
116
117 msgid "'Your command, please?', asked the waiter."
118 msgstr "«Votre commande, s'il vous plait», dit le garçon."
119
120 # Les gateaux allemands sont les meilleurs du monde.
121 #, java-format
122 msgid "a piece of cake"
123 msgid_plural "{0,number} pieces of cake"
124 msgstr[0] "un morceau de gateau"
125 msgstr[1] "{0,number} morceaux de gateau"
126
127 # Reverse the arguments.
128 #, java-format
129 msgid "{0} is replaced by {1}."
130 msgstr "{1} remplace {0}."
131
132 # Euphemistic formulation.
133 #, java-format
134 msgctxt "++"
135 msgid "a piece of cake"
136 msgid_plural "{0,number} pieces of cake"
137 msgstr[0] "un morceau de gateau succulent"
138 msgstr[1] "{0,number} morceaux de gateau succulent"
139
140 # Euphemistic formulation.
141 #, java-format
142 msgctxt "++"
143 msgid "{0} is replaced by {1}."
144 msgstr "Le nouveau {1} remplace le vieux {0}."
145 EOF
146
147 tmpfiles="$tmpfiles l-java-fr.po.tmp l-java-fr.po.new"
148 : ${MSGMERGE=msgmerge}
149 ${MSGMERGE} -q -o l-java-fr.po.tmp l-java-fr.po l-java-prog.pot
150 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
151 LC_ALL=C tr -d '\r' < l-java-fr.po.tmp > l-java-fr.po.new
152 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
153
154 : ${DIFF=diff}
155 ${DIFF} l-java-fr.po l-java-fr.po.new || exit 1
156
157 tmpfiles="$tmpfiles prog_fr.class"
158 : ${MSGFMT=msgfmt}
159 ${MSGFMT} -j -d l-java -r prog -l fr l-java-fr.po || exit 1
160
161 # Test which of the fr_FR locales are installed.
162 : ${LOCALE_FR=fr_FR}
163 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
164 if test $LOCALE_FR != none; then
165   LC_ALL=$LOCALE_FR ./testlocale
166   case $? in
167     0) ;;
168     77) LOCALE_FR=none;;
169     *) exit 1;;
170   esac
171 fi
172 if test $LOCALE_FR_UTF8 != none; then
173   LC_ALL=$LOCALE_FR_UTF8 ./testlocale
174   case $? in
175     0) ;;
176     77) LOCALE_FR_UTF8=none;;
177     *) exit 1;;
178   esac
179 fi
180 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
181   if test -f /usr/bin/localedef; then
182     echo "Skipping test: no french locale is installed"
183   else
184     echo "Skipping test: no french locale is supported"
185   fi
186   rm -fr $tmpfiles; exit 77
187 fi
188
189 tmpfiles="$tmpfiles l-java-prog.ok l-java-prog.oku l-java-prog.out"
190 : ${DIFF=diff}
191 cat <<\EOF > l-java-prog.ok
192 «Votre commande, s'il vous plait», dit le garçon.
193 2 morceaux de gateau
194 EUR remplace FF.
195 2 morceaux de gateau succulent
196 Le nouveau EUR remplace le vieux FF.
197 EOF
198 cat <<\EOF > l-java-prog.oku
199 «Votre commande, s'il vous plait», dit le garçon.
200 2 morceaux de gateau
201 EUR remplace FF.
202 2 morceaux de gateau succulent
203 Le nouveau EUR remplace le vieux FF.
204 EOF
205
206 : ${LOCALE_FR=fr_FR}
207 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
208 : ${JAVAEXEC="/bin/sh ../javaexec.sh"}
209 if test $LOCALE_FR != none; then
210   LANGUAGE= LC_ALL=$LOCALE_FR CLASSPATH=l-java:../../gettext-runtime/intl-java/libintl.jar ${JAVAEXEC} Program 2 ISO-8859-1 > l-java-prog.out || exit 1
211   ${DIFF} l-java-prog.ok l-java-prog.out || exit 1
212 fi
213 if test $LOCALE_FR_UTF8 != none; then
214   LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 CLASSPATH=l-java:../../gettext-runtime/intl-java/libintl.jar ${JAVAEXEC} Program 2 UTF-8 > l-java-prog.out || exit 1
215   ${DIFF} l-java-prog.oku l-java-prog.out || exit 1
216 fi
217
218 rm -fr $tmpfiles
219
220 exit 0