Are there any constants for language codes like "en"
or "de"
in java or in a java library? (Or is using the strings OK?)
I know that something like
Locale.COUNTRY-NAME.getLanguage()
would work, but I am searching for something more streamlined like
Locale.LANGUAGE-NAME
setDefault(java. util. Locale. ENGLISH); JFileChooser chooser = new JFileChooser(); chooser.
Setting a thread's locale or changing your system locale will change how numbers, dates, and times are displayed for controls created on that thread or running on your system, respectively. A language, on the other hand, is what we speak, read, and write.
A Locale object represents a specific geographical, political, or cultural region. An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to tailor information for the user.
To get equivalent information in Java, use Locale. getDefault() to get the Locale that Java is using, and use methods on the Locale object such as getCountry() , getLanguage() to get details. The information is available using ISO codes and as human readable/displayable names.
I am afraid there aren't constants for all languages.
You do have several predefined Locales such as Locale.UK
Locale.US
, etc. Each locale has a language code which can be obtained via the getLanguage()
method.
To get all language code supported by the underlying JVM use getISOLanguages()
for(String lang : Locale.getISOLanguages()) {
System.out.println(lang);
}
More details: http://download.oracle.com/javase/1.4.2/docs/api/java/util/Locale.html
The 2-letter language codes are defined by ISO 639-1 standard. The java.util.Locale
class does not contain them all, but only Locales supported by the VM (as per Locale.getAvailableLocales()
).
The easiest way to access all ISO 639-1 language codes in Java is to rely on the International Components for Unicode project (ICU4J) — an extensive, widely used and actively developed i18n library from IBM. You can get the list of all languages from the ULocale class: com.ibm.icu.util.ULocale.getISOLanguages().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With