i18n problem, involving Locale.getDisplayLanguage and Locale.getDisplayCountry
2 Message(s) by 2 Author(s) originally posted in java api
| From: Maurice Hulsman |
Date: Monday, July 19, 2004
|
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 does not, I'd
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 is not 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 not imagine sun proposes such a way.
I can not find any references to how this should be done properly.
Maurice Hulsman
maurice.hulsman@xxxxxxxxxxx
*) if somebody'd like to know exactly what we did, you can always ask
| From: Guus Bosman |
Date: Sunday, July 25, 2004
|
Hi Maurice,
There is no "official" way to reach your
goal here. According to the
API (application
programming interface)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 do not
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 does not
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'd 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> 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 does not, I'd 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 is not 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 not imagine sun proposes such a way.
I can not find any references to how this should be done properly.
Maurice Hulsman
maurice.hulsman@xxxxxxxxxxx
*) if somebody'd like to know exactly what we did, you can always ask
>
Next Message: JAVA Hashtable performance for contains() method.