How can I get a list of full names of languages? I checked Locale
class and found getISOLanguages()
, but it returns 2-letter language codes (for instance, 'en') when I need full name of language (for example, 'English').
What is the better approach for that?
Finally, thanks to Thomas comments I implemented it in such way:
SortedSet<String> allLanguages = new TreeSet<String>();
String[] languages = Locale.getISOLanguages();
for (int i = 0; i < languages.length; i++){
Locale loc = new Locale(languages[i]);
allLanguages.add(loc.getDisplayLanguage());
}
UPD. Also there is the more modern style:
Set<String> languages = Arrays.stream(Locale.getISOLanguages())
.map(Locale::new)
.map(Locale::getDisplayLanguage)
.collect(Collectors.toCollection(TreeSet::new));
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