How to get list of all the installed or supported languages that are listed under "Language and Input settings" programmatically in android.
I have used Resources.getSystem().getAssets().getLocales() but it gives me only code of that language like en, en_us but I need both code and display name.
I have also tried with Locale.getAvailableLocales() but it gives me repeated items and too big list.
Please tell me what is the correct way of doing this.
getAvailableLocales()
gives you all Languages,but as one/more countries can have same language,it is repeated,you can filter it using
public ArrayList<String> getAllLanguages()
{
Locale[] locales = Locale.getAvailableLocales();
ArrayList<String> languages=new ArrayList<String>();
for(Locale temp : locales)
{
if(!languages.Contains(temp.getDisplayLanguage()))
languages.Add(temp.getDisplayLanguage());
}
return languages;
}
Okay ,This will work to get Languages under input Settings
private ArrayList<String> getInputLanguages() {
ArrayList<String> inputlanguages=new ArrayList<String>();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
List<InputMethodInfo> ims = imm.getEnabledInputMethodList();
for (InputMethodInfo method : ims){
List<InputMethodSubtype> submethods = imm.getEnabledInputMethodSubtypeList(method, true);
for (InputMethodSubtype submethod : submethods){
if (submethod.getMode().equals("keyboard")){
String currentLocale = submethod.getLocale();
Locale locale = new Locale(localeString);
String currentLanguage = locale.getDisplayLanguage();
inputlanguages.Add(currentLanguage );
}
}
}
return inputlangauges;
}
Yes you can get the list same as under languageand input settings by
using
String[] systemLocaleIetfLanguageTags = Resources.getSystem().getAssets().getLocales();