i18n problem, involving Locale.getDisplayLanguage and Locale.getDisplayCountry

Skip to first unread message

Maurice Hulsman

Jul 19, 2004, 8:16:10 AM7/19/04

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

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

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

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

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

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

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
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:11:14 PM7/25/04
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. "


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?

Guus Bosman


"Maurice Hulsman" <maurice...@indicia.nl> wrote in message

Reply all
Reply to author
0 new messages