How to get programmatically list of supported languages in an Android project (NOT device)

ぃ、小莉子 提交于 2019-12-05 15:11:35

问题


In some project we can have this situation

How to get programmatically list of supported languages by this app/project? As the result I need string array like this

{ "en", "bg", "bs", "da", "de", "hr", "it", "nl", "pl", "pt", "sk", "sr", "tr" }

Of course I can hardcode it by typing it but I suppose code can and should do it.

And why I need it - I have a separate library that deals with localization, instant change of UI after selecting new language etc. App must tell library which languages it supports. And it's nice just to add new xml for a new language without changing code (updating that hardcoded list).


回答1:


this code could help :

    String lang =getApplicationContext().getResources().getConfiguration().getLocales().toLanguageTags();
    String langs[] = lang.split(",");


来源:https://stackoverflow.com/questions/30375274/how-to-get-programmatically-list-of-supported-languages-in-an-android-project-n

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