i18n problem, involving Locale.getDisplayLanguage and Locale.getDisplayCountry

0 views
Skip to first unread message

Maurice Hulsman

unread,
Jul 19, 2004, 8:16:10 AM7/19/04
to
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
maurice...@indicia.nl

*) if somebody would like to know exactly what we did, you can always ask


Guus Bosman

unread,
Jul 25, 2004, 2:11:14 PM7/25/04
to
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" <maurice...@indicia.nl> wrote in message
news:40fbbb8e$0$48933$e4fe...@news.xs4all.nl...

Reply all
Reply to author
Forward
0 new messages