users@jsr311.java.net

Re: Languages that are not Locale

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

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.