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