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.
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.
11 trap 'rm -fr $tmpfiles' 1 2 3 15
13 # Test whether we can build and test Java programs.
14 test "${JAVA_CHOICE}" != no || {
15 echo "Skipping test: configured with --disable-java"
18 test "${BUILDJAVA}" = yes || {
19 echo "Skipping test: Java compiler or jar not found"
22 test "${TESTJAVA}" = yes || {
23 echo "Skipping test: Java engine not found"
27 tmpfiles="$tmpfiles Program.java"
28 cat <<\EOF > Program.java
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"));
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.
46 System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out),
48 } catch (UnsupportedEncodingException e) {
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" }));
65 tmpfiles="$tmpfiles Program.class l-java l-java-prog.err"
66 test -d l-java || mkdir l-java
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; }
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; }
79 tmpfiles="$tmpfiles l-java-prog.ok"
80 cat <<EOF > l-java-prog.ok
81 msgid "'Your command, please?', asked the waiter."
85 msgid "a piece of cake"
86 msgid_plural "{0,number} pieces of cake"
91 msgid "{0} is replaced by {1}."
96 msgid "a piece of cake"
97 msgid_plural "{0,number} pieces of cake"
103 msgid "{0} is replaced by {1}."
108 ${DIFF} l-java-prog.ok l-java-prog.pot || exit 1
110 tmpfiles="$tmpfiles l-java-fr.po"
111 cat <<\EOF > l-java-fr.po
114 "Content-Type: text/plain; charset=ISO-8859-1\n"
115 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
117 msgid "'Your command, please?', asked the waiter."
118 msgstr "«Votre commande, s'il vous plait», dit le garçon."
120 # Les gateaux allemands sont les meilleurs du monde.
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"
127 # Reverse the arguments.
129 msgid "{0} is replaced by {1}."
130 msgstr "{1} remplace {0}."
132 # Euphemistic formulation.
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"
140 # Euphemistic formulation.
143 msgid "{0} is replaced by {1}."
144 msgstr "Le nouveau {1} remplace le vieux {0}."
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; }
155 ${DIFF} l-java-fr.po l-java-fr.po.new || exit 1
157 tmpfiles="$tmpfiles prog_fr.class"
159 ${MSGFMT} -j -d l-java -r prog -l fr l-java-fr.po || exit 1
161 # Test which of the fr_FR locales are installed.
163 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
164 if test $LOCALE_FR != none; then
165 LC_ALL=$LOCALE_FR ./testlocale
172 if test $LOCALE_FR_UTF8 != none; then
173 LC_ALL=$LOCALE_FR_UTF8 ./testlocale
176 77) LOCALE_FR_UTF8=none;;
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"
184 echo "Skipping test: no french locale is supported"
186 rm -fr $tmpfiles; exit 77
189 tmpfiles="$tmpfiles l-java-prog.ok l-java-prog.oku l-java-prog.out"
191 cat <<\EOF > l-java-prog.ok
192 «Votre commande, s'il vous plait», dit le garçon.
195 2 morceaux de gateau succulent
196 Le nouveau EUR remplace le vieux FF.
198 cat <<\EOF > l-java-prog.oku
199 «Votre commande, s'il vous plait», dit le garçon.
202 2 morceaux de gateau succulent
203 Le nouveau EUR remplace le vieux FF.
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
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