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