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