I am trying to convert the locale tags (see picture) to display names. For instance, instead of en-us I would like to display English (USA). So far I have managed to get a mixture of display names and language tags as in the picture:
device system languages screen picture
I have tried many thing such as using forLanguageTag, getDisplayLanguage + getDisplayCountry but nothing works.
This is my code snippet:
public void getAvailableLocales() {
systemLanguages = Resources.getSystem().getAssets().getLocales();
Arrays.sort(systemLanguages);
for (int i = 0; i < systemLanguages.length; i++) {
String sL = systemLanguages[i];
Locale loc = new Locale(sL);
String locDisplayResults = loc.getDisplayLanguage();
languagesList.add(new Languages(locDisplayResults));
recyclerAdapter.notifyDataSetChanged();
}
}
The idea is to display all languages available on a given device. Any help would be gratefully received.
Edit: Testing shows that Resources.getSystem().getAssets().getLocales() does indeed give the languages available for each given device. However, getDisplayLanguage only works for two letter tags, and not for two letters-dash-two letters (eg. ar-eg). Any more ideas?
Try
Locale[] availableLocales = Locale.getAvailableLocales();
for(Locale locale : availableLocales){
Log.d("Locale", locale.getDisplayName());
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.