i18n problem, involving Locale.getDisplayLanguage and Locale.getDisplayCountry

M

Maurice Hulsman

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")))

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

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

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

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
(e-mail address removed)

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

Guus Bosman

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top