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