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

懵懂的女人 提交于 2019-12-18 04:33:31

问题


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?


回答1:


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

//...


来源:https://stackoverflow.com/questions/36061116/get-language-name-in-that-language-from-language-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!