users@jsr311.java.net

Re: Languages that are not Locale

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Wed, 15 Oct 2008 09:52:04 -0400

On Oct 15, 2008, at 9:38 AM, Reto Bachmann-Gmür wrote:

> hmm,
> http://java.sun.com/javase/6/docs/api/java/util/Locale.html#Locale(java.lang.String)
> specifies the argument language to be "lowercase two-letter ISO-639
> code.", also getLanguage is defined two return an ISO 639 code.
>
> But the behaviour of the implementation seems reasonable.

There's also this in the class Javadoc:

"Because a Locale object is just an identifier for a region, no
validity check is performed when you construct a Locale. If you want
to see whether particular resources are available for the Locale you
construct, you must query those resources."

Marc.

>
> Marc Hadley said the following on 2008-10-15 15:33:
>> On Oct 15, 2008, at 8:06 AM, Reto Bachmann-Gmür wrote:
>>
>>> java.util.Locale "represents a specific geographical, political, or
>>> cultural region", languages in HTTP (and in RFC 4646) are not
>>> exactly
>>> the same, so in some cases a language cannot be mapped to a Locale
>>> (such
>>> as "i-klingon" or language with only a 3-letter code). I guess the
>>> api
>>> for HttpHeaders should define what do do with such languages, and
>>> suggest getLanguage() returns null qnd
>>> getAcceptableLanguages() an
>>> iterator without the languages that cannot be represented as
>>> Locale. Or
>>> should an issue be raised against java.util.Locale?
>>>
>> Locale works fine with non-standard languages:
>>
>> bash$ bsh
>> BeanShell 2.0b4 - by Pat Niemeyer (pat_at_pat.net)
>> bsh % l = new Locale("i-klingon");
>> bsh % print(l);
>> i-klingon
>> bsh % print(l.getLanguage());
>> i-klingon
>> bsh % print(l.getCountry());
>>
>> bsh % print(l.getDisplayName());
>> i-klingon
>> bsh % print(l.getDisplayLanguage());
>> i-klingon
>>
>> You only run into problems when you try to convert to ISO codes but
>> that
>> exception is expected:
>>
>> bsh % print(l.getISO3Language());
>> // Error: // Uncaught Exception: Method Invocation
>> l.getISO3Language :
>> at Line: 7 : in file: <unknown file> : l .getISO3Language ( )
>>
>> Target exception: java.util.MissingResourceException: Couldn't find
>> 3-letter language code for i-klingon
>>
>> Marc.
>>
>> ---
>> Marc Hadley <marc.hadley at sun.com>
>> CTO Office, Sun Microsystems.
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jsr311.dev.java.net
>> For additional commands, e-mail: users-help_at_jsr311.dev.java.net
>>
>

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.