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[56]*) 42 cat <<\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 } 50 EOF 51 ;; 52 darwin*) 53 cat <<\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 } 61 EOF 62 ;; 63 esac 64 cat <<\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 } 72 EOF 73 74 tmpfiles="$tmpfiles Program.class" 75 : ${JAVACOMP="/bin/sh ../javacomp.sh"} 76 CLASSPATH=../../gettext-runtime/intl-java/libintl.jar ${JAVACOMP} -d . Program.java || exit 1 77 78 tmpfiles="$tmpfiles prog.pot" 79 : ${XGETTEXT=xgettext} 80 ${XGETTEXT} -o prog.pot --omit-header --no-location Program.java 81 82 tmpfiles="$tmpfiles prog.ok" 83 cat <<EOF > prog.ok 84 msgid "'Your command, please?', asked the waiter." 85 msgstr "" 86 87 #, java-format 88 msgid "a piece of cake" 89 msgid_plural "{0,number} pieces of cake" 90 msgstr[0] "" 91 msgstr[1] "" 92 93 #, java-format 94 msgid "{0} is replaced by {1}." 95 msgstr "" 96 EOF 97 98 : ${DIFF=diff} 99 ${DIFF} prog.ok prog.pot || exit 1 100 101 tmpfiles="$tmpfiles fr.po" 102 cat <<\EOF > fr.po 103 msgid "" 104 msgstr "" 105 "Content-Type: text/plain; charset=ISO-8859-1\n" 106 "Plural-Forms: nplurals=2; plural=(n > 1);\n" 107 108 msgid "'Your command, please?', asked the waiter." 109 msgstr "Votre commande, s'il vous plait, dit le garon." 110 111 # Les gateaux allemands sont les meilleurs du monde. 112 #, java-format 113 msgid "a piece of cake" 114 msgid_plural "{0,number} pieces of cake" 115 msgstr[0] "un morceau de gateau" 116 msgstr[1] "{0,number} morceaux de gateau" 117 118 # Reverse the arguments. 119 #, java-format 120 msgid "{0} is replaced by {1}." 121 msgstr "{1} remplace {0}." 122 EOF 123 124 tmpfiles="$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 131 tmpfiles="$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} 138 if 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 145 fi 146 if 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 153 fi 154 if 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 161 fi 162 163 tmpfiles="$tmpfiles prog.ok prog.oku prog.out" 164 : ${DIFF=diff} 165 cat <<\EOF > prog.ok 166 Votre commande, s'il vous plait, dit le garon. 167 2 morceaux de gateau 168 EUR remplace FF. 169 EOF 170 cat <<\EOF > prog.oku 171 Votre commande, s'il vous plait, dit le garon. 172 2 morceaux de gateau 173 EUR remplace FF. 174 EOF 175 176 : ${LOCALE_FR=fr_FR} 177 : ${LOCALE_FR_UTF8=fr_FR.UTF-8} 178 : ${JAVAEXEC="/bin/sh ../javaexec.sh"} 179 if 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 182 fi 183 if 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 186 fi 187 188 rm -fr $tmpfiles 189 190 exit 0 191