Re: MessageFormat boolean and hex

Discussion in 'Java' started by Jon A. Cruz, Aug 9, 2003.

  1. Jon A. Cruz

    Jon A. Cruz Guest

    cody wrote:
    > why not simply
    >
    > MessageFormat.format( "{0}", new Object[] { writeonly ? "Read-Only" :
    > "Read-Write" });
    >
    > ?



    Well, one reason could be due to the need for internationalization (much
    of the reason for using MessageFormat).

    In general, an application would load the format string from a resource
    bundle of some type. This would then be changed per language and per
    locale, with the text and order being changed.

    By hardcoding the "Read-Only" and "Read-Write" text in the program code
    itself, you suddenly loose that.
     
    Jon A. Cruz, Aug 9, 2003
    #1
    1. Advertising

  2. Jon A. Cruz

    Jon A. Cruz Guest

    Jon A. Cruz wrote:
    > By hardcoding the "Read-Only" and "Read-Write" text in the program code
    > itself, you suddenly loose that.



    I just realized the first of the OP's requests can be achieved using
    existing support:


    MessageFormat.format( "{0,choice,0#read-only|1#read-write}", new
    Object[] { new Integer(writeable?1:0) });


    Just a slight variation on what Cody posted.
     
    Jon A. Cruz, Aug 9, 2003
    #2
    1. Advertising

  3. Jon A. Cruz

    cody Guest

    > cody wrote:
    > > why not simply
    > >
    > > MessageFormat.format( "{0}", new Object[] { writeonly ? "Read-Only" :
    > > "Read-Write" });
    > >
    > > ?

    >
    >
    > Well, one reason could be due to the need for internationalization (much
    > of the reason for using MessageFormat).
    >
    > In general, an application would load the format string from a resource
    > bundle of some type. This would then be changed per language and per
    > locale, with the text and order being changed.
    >
    > By hardcoding the "Read-Only" and "Read-Write" text in the program code
    > itself, you suddenly loose that.


    but your proposal has the same problem:

    > MessageFormat.format( "{0,choice,0#read-only|1#read-write}", new
    > Object[] { new Integer(writeable?1:0) });


    but how about that:

    MessageFormat.format( "{0}", new Object[] { writeonly ? LoadString(ReadOnly)
    : LoadString(ReadWrite) });


    --
    cody

    [Freeware, Games and Humor]
    www.deutronium.de.vu || www.deutronium.tk
     
    cody, Aug 10, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Panda
    Replies:
    1
    Views:
    1,677
    Roedy Green
    Sep 2, 2003
  2. Ittay Dror
    Replies:
    1
    Views:
    440
    Ittay Dror
    Jul 29, 2004
  3. spring MessageFormat

    , Feb 8, 2006, in forum: Java
    Replies:
    0
    Views:
    1,742
  4. Replies:
    10
    Views:
    6,222
    Neredbojias
    Aug 19, 2005
  5. Bengt Richter
    Replies:
    6
    Views:
    473
    Juha Autero
    Aug 19, 2003
Loading...

Share This Page