I18N Question re presenting time remaining

Discussion in 'Java' started by Rhino, Feb 10, 2005.

  1. Rhino

    Rhino Guest

    I am writing an application in which I want to present a value that
    represents the time remaining on a task, expressed in hours, minutes, and
    seconds. In English, this would typically be presented as follows:

    The time remaining is 4:05:24 (hours:minutes:seconds).

    [I plan to include a bracketed string like '(hours:minutes:seconds)',
    translated to the appropriate language, for each locale that I support, just
    to make sure no one mistakenly assumes I mean 4 minutes, 5 seconds, and 24
    hundreds - or 4 days, 5 hours, and 24 minutes!]

    However, I feel sure that other locales will use different characters (or
    spaces) in place of the colons that we use in English in presenting this
    information.

    Does anyone know how I can determine what 'punctuation' (for want of a
    better term) I should be using for each locale and, especially, what Java
    methods will determine the appropriate punctuation for a given locale?

    --
    Rhino
    ---
    rhino1 AT sympatico DOT ca
    "There are two ways of constructing a software design. One way is to make it
    so simple that there are obviously no deficiencies. And the other way is to
    make it so complicated that there are no obvious deficiencies." - C.A.R.
    Hoare
     
    Rhino, Feb 10, 2005
    #1
    1. Advertising

  2. Rhino wrote:
    > Does anyone know how I can determine what 'punctuation' (for want of a
    > better term) I should be using for each locale and, especially, what Java
    > methods will determine the appropriate punctuation for a given locale?


    To the best of my knowledge, there is no (simple) way to get that
    information in Java. You can get a particular time format via
    DateFormat.getTimeInstance(SHORT). But, and that is a big *BUT*, this
    time format is intended for wall clock time. E.g. in countries with a
    12hour time format you will get a format which includes the am/pm string
    in that locale. And that one is totally unusable for displaying the
    remaining time.

    Java gets the defaults for these DateFormat instances from some internal
    resource bundle, which does not have a public API.

    You could try to get some clues out of the format pattern from the
    particular DateFormat instance, but that would be rather ugly hack.

    /Thomas

    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
     
    Thomas Weidenfeller, Feb 11, 2005
    #2
    1. Advertising

  3. Rhino

    Rhino Guest

    "Thomas Weidenfeller" <> wrote in message
    news:cuhsi7$d2n$...
    > Rhino wrote:
    > > Does anyone know how I can determine what 'punctuation' (for want of a
    > > better term) I should be using for each locale and, especially, what

    Java
    > > methods will determine the appropriate punctuation for a given locale?

    >
    > To the best of my knowledge, there is no (simple) way to get that
    > information in Java. You can get a particular time format via
    > DateFormat.getTimeInstance(SHORT). But, and that is a big *BUT*, this
    > time format is intended for wall clock time. E.g. in countries with a
    > 12hour time format you will get a format which includes the am/pm string
    > in that locale. And that one is totally unusable for displaying the
    > remaining time.
    >
    > Java gets the defaults for these DateFormat instances from some internal
    > resource bundle, which does not have a public API.
    >
    > You could try to get some clues out of the format pattern from the
    > particular DateFormat instance, but that would be rather ugly hack.
    >
    > /Thomas


    Thanks, Thomas, for confirming what I suspected.

    I did something similar to what you suggested: I used a DateFormatter on an
    arbitrary date that was set to 1:00 AM, then parsed the resulting formatted
    string for the first character after '1' to see what the punctuation for
    that locale was. As a safeguard, I checked to make sure that the character
    was not a letter or digit: if it is, I return a blank instead of whatever
    character I found by parsing. This approach seemed like it should be safe
    for any presentation of a time that I can imagine but, of course, I don't
    know the actual local formats for all of Java's different locales so I could
    be wrong ;-)

    In any case, the worst that will happen with this approach is that the time
    remaining will be formatted a bit strangely in some locales, assuming I ever
    support those locales in the first place.

    Rhino
     
    Rhino, Feb 11, 2005
    #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. Jim Higson
    Replies:
    2
    Views:
    422
    Jukka K. Korpela
    Aug 23, 2004
  2. Replies:
    4
    Views:
    628
  3. Ingvald Straume (from Norway - Europe)

    Presenting a new(?) idea for free open source software development.

    Ingvald Straume (from Norway - Europe), Aug 7, 2005, in forum: C++
    Replies:
    10
    Views:
    601
    Ingvald Straume (from Norway - Europe)
    Aug 9, 2005
  4. maudrit
    Replies:
    0
    Views:
    318
    maudrit
    Mar 4, 2007
  5. Mike Barnard
    Replies:
    4
    Views:
    398
    Mike Barnard
    May 3, 2007
Loading...

Share This Page