i18n problem, involving Locale.getDisplayLanguage and Locale.getDisplayCountry

Discussion in 'Java' started by Maurice Hulsman, Jul 19, 2004.

  1. LS,

    concider the following (ran on a winxp machine under jdk1.3.1)

    1: out.println(new Locale("nl", "BE").getDisplayLanguage(new Locale("en",
    "US")))
    > Belgium


    2: out.println(new Locale("nl", "BE").getDisplayLanguage(new Locale("nl",
    "NL")))
    > Belgiƫ


    3: out.println(new Locale("en", "US").getDisplayLanguage(new Locale("en",
    "US")))
    > english


    4: out.println(new Locale("en", "US").getDisplayLanguage(new Locale("nl",
    "NL")))
    > english


    line 1, 2 and 3 function properly
    line 4 doesn't, I would expect "engels" (which is the dutch translation of
    "english")

    we already determined this behaviour is caused by the
    <java_home>/jre/lib/i18n.jar, which isn't fitted with al of the language
    specific details.
    We know this because when I unpack the jar, decompile the class
    java.text.resources.LocaleElements_nl, add translation "engels"* and compile
    and jar again, line 4 functions properly

    my question is as follows:

    Does anybody know the proper way to do this, eg: without decompiling the
    i18n.jar
    I can't imagine sun proposes such a way.
    I can't find any references to how this should be done properly.

    Maurice Hulsman


    *) if somebody would like to know exactly what we did, you can always ask
     
    Maurice Hulsman, Jul 19, 2004
    #1
    1. Advertising

  2. Maurice Hulsman

    Guus Bosman Guest

    Hi Maurice,

    There is no "official" way to reach your goal here. According to the API of
    Locale, the method getDisplayLanguage(Locale inLocale) will give a
    best-effort result:

    "Returns a name for the locale's language that is appropriate for display to
    the user. If possible, the name returned will be localized for the default
    locale. For example, if the locale is fr_FR and the default locale is en_US,
    getDisplayLanguage() will return "French"; if the locale is en_US and the
    default locale is fr_FR, getDisplayLanguage() will return "anglais". If the
    name returned cannot be localized for the default locale, (say, we don't
    have a Japanese name for Croatian), this function falls back on the English
    name, and uses the ISO code as a last-resort value. If the locale doesn't
    specify a language, this function returns the empty string. "

    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Locale.html#getDisplayName(java.util.Locale)

    An easy solution would of course be not to use
    Locale#getDisplayLanguage(Locale inLocale) but use your own decorator class.
    Are there any reasons this won't work for you?

    Regards,
    Guus Bosman

    http://www.guusbosman.nl


    "Maurice Hulsman" <> wrote in message
    news:40fbbb8e$0$48933$4all.nl...
    > LS,
    >
    > concider the following (ran on a winxp machine under jdk1.3.1)
    >
    > 1: out.println(new Locale("nl", "BE").getDisplayLanguage(new Locale("en",
    > "US")))
    > > Belgium

    >
    > 2: out.println(new Locale("nl", "BE").getDisplayLanguage(new Locale("nl",
    > "NL")))
    > > Belgiƫ

    >
    > 3: out.println(new Locale("en", "US").getDisplayLanguage(new Locale("en",
    > "US")))
    > > english

    >
    > 4: out.println(new Locale("en", "US").getDisplayLanguage(new Locale("nl",
    > "NL")))
    > > english

    >
    > line 1, 2 and 3 function properly
    > line 4 doesn't, I would expect "engels" (which is the dutch translation of
    > "english")
    >
    > we already determined this behaviour is caused by the
    > <java_home>/jre/lib/i18n.jar, which isn't fitted with al of the language
    > specific details.
    > We know this because when I unpack the jar, decompile the class
    > java.text.resources.LocaleElements_nl, add translation "engels"* and

    compile
    > and jar again, line 4 functions properly
    >
    > my question is as follows:
    >
    > Does anybody know the proper way to do this, eg: without decompiling the
    > i18n.jar
    > I can't imagine sun proposes such a way.
    > I can't find any references to how this should be done properly.
    >
    > Maurice Hulsman
    >
    >
    > *) if somebody would like to know exactly what we did, you can always ask
    >
    >
    >
    >
     
    Guus Bosman, Jul 25, 2004
    #2
    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. =?ISO-8859-1?Q?Phil_H=FChn?=

    i18n: Fallback more than 1 locale?

    =?ISO-8859-1?Q?Phil_H=FChn?=, Jun 3, 2004, in forum: Java
    Replies:
    3
    Views:
    817
    =?ISO-8859-1?Q?Phil_H=FChn?=
    Jun 6, 2004
  2. Replies:
    4
    Views:
    1,054
  3. Gabriel Genellina
    Replies:
    0
    Views:
    743
    Gabriel Genellina
    Feb 18, 2009
  4. zade
    Replies:
    1
    Views:
    647
    James Kanze
    Mar 5, 2010
  5. Sibylle Koczian
    Replies:
    2
    Views:
    1,164
    Sibylle Koczian
    Nov 20, 2010
Loading...

Share This Page