Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4105380

RFE: Subformats attached to MessageFormat should be numbered by argument number

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      sparc
    • OS:
      solaris_2.6

      Description


      Name: jh38747 Date: 01/21/98


      When using ChoiceFormat, class java.text.MessageFormat is very inconvenient for i18n programming. As we kown, in different languages, the arguments in the same text will be in different displayed order. For instance, we have two pattern text of two languages, and they signify the same meaning.

      patternText1 = "The disk \"{1}\" contains {0}.";// for english
      patternText2 = "There are {0} on the disk \"{1}\"";//for one of other languages

      Then we can construct two MessageFormat objects:
      MessageFormat form1 = new MessageFormat(patternText1);
      MessageFormat form2 = new MessageFormat(patternText2);

      Now we want to use ChoiceFormat in these two MessageFormat objects, so we construct a ChoiceFormat object:
      double[] filelimits = {0,1,2};
      String[] filepart = {"no files","one file","{0,number} files"};
      ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart);

      If we wanted the argument {1} in two MessageFormat objects to be this ChoiceFormat format, let's see what we should do in our current JDK.
      form1.setFormat(1, fileform); // (1)
      form2.setFormat(0, fileform); // (2)
      the digit in formula (1) and (2) is different, because argument {1} are
      displayed in different order in the two pattern text.

      So, if we use ChoiceFormat in MessageFormat, and we have 1000 pattern text, and
      unfortunately we have 1000 display order of the argument as {1}, we have to
      rewrite the formula in our source code like above formula (1) and (2).
      It is realy very inconvenient.
       
      Why not define the method setFormat as follows:
      MessageFormat.setFormat(int num, ChoiceFormat fileform)
      where num is just the definition order not the display order.

      =========================t2.java====================================
      import java.text.*;
      import java.util.*;

      public class t2 {
      public static void main(String args[]) {
      String patternText1 = "The disk \"{1}\" contains {0}.";
      String patternText2 = "There are {0} on the disk \"{1}\"";
      MessageFormat form1 = new MessageFormat(patternText1);
      MessageFormat form2 = new MessageFormat(patternText2);
      double[] filelimits = {0,1,2};
      String[] filepart = {"no files","one file","{0,number} files"};
      ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart);
      form1.setFormat(1, fileform);
      form2.setFormat(0, fileform);
      Object[] testArgs = {new Long(12373), "MyDisk"};
      System.out.println(form1.format(testArgs));
      System.out.println(form2.format(testArgs));
      }
      }
      ===============================================================================

        Attachments

          Activity

            People

            Assignee:
            nlindenbsunw Norbert Lindenberg (Inactive)
            Reporter:
            jhusunw Jim Hu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: