Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get language name in that language from language code [duplicate]

I have a list of language codes (as in "en", "es"...) I need to display in those language like this:

English
Español
Français
Deutsch
日本語

Is there any built-in API to get these in Android or should I map them myself?

like image 448
Charlie-Blake Avatar asked Mar 17 '16 12:03

Charlie-Blake


1 Answers

The Locale class have a method for this: public String getDisplayLanguage(Locale locale), as the documentation says:

Returns the name of this locale's language, localized to locale. The exact output form depends on whether this locale corresponds to a specific language, script, country and variant.

So you can get language names for locales like this:

String lng = "en";
Locale loc = new Locale(lng);
String name = loc.getDisplayLanguage(loc); // English

lng = "es";
loc = new Locale(lng);
name = loc.getDisplayLanguage(loc); // español

//...
like image 114
nvi9 Avatar answered Oct 17 '22 21:10

nvi9