Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standardized java enum for ISO language codes?

I'd like to be able to reference languages in a standardized way (ISO). Is there an existing enumeration as part of java or a common dependency such as Apache that I can reuse rather than having to implement my own?

To emphasize, I'm not looking for countries, but for languages!

like image 801
Andreas Hartmann Avatar asked Dec 14 '18 12:12

Andreas Hartmann


People also ask

Why we should not use enum in Java?

If you ever need to change the value of a String constant, it is a one-line change. With an enum it can get more complicated due to having separate values for name and toString, and those values possibly being used in conditional logic.

What is locale Java?

The Java Locale class object represents a specific geographic, cultural, or political region. It is a mechanism to for identifying objects, not a container for the objects themselves. A Locale object logically consists of the fields like languages, script, country, variant, extensions.

How do I get the locale in Java?

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.

What is an enum Java?

An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week.


Video Answer


1 Answers

How about the Locale.getISOLanguages() which covers ISO 639. However, it's not an enum but the String array (String[]).

Returns a list of all 2-letter language codes defined in ISO 639. Can be used to create Locales.

like image 94
Nikolas Charalambidis Avatar answered Oct 21 '22 10:10

Nikolas Charalambidis