I have an app that needs to support Engligh, Spanish, and Russian.
To detect this, I use this method:
UserLanguage = setLanguage(Locale.getDefault().getDisplayLanguage());
UserLanguage is "en" if English, "es" is Spanish, and it needs to be "ru" if Russian, otherwise it will be English. However, when I set the locale on my phone to Russian, it is not detected. The documentation on the Android website does not say anything about Russian. Any help?
private String setLanguage(String locale){
//Toast.makeText(context, locale.toString(), Toast.LENGTH_SHORT).show();
if(locale.equals("English")){
UserLanguage="en";
}else{
if(locale.equals("español")){//espanol
UserLanguage="es";
}else{
if(locale.equals("ru")){//cant compile with true russian
UserLanguage="ru";
}else{
//I give up.... english??
UserLanguage="en";
}
}
}
return UserLanguage;
}
For Russian Locale.getDefault().getDisplayLanguage() will return "русский"
Try this instead:
But much better solution is to use getLanguage(), instead of getDisplayLanguage():