Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for a device language in android?

I want my application to check which language the phone is using. This if statement is supposed to do that:

 if (Locale.getDefault().getLanguage().equals("en")) {
     yourYesResponse = "That is great " + usersName + "!";
 }
 else if (Locale.getDefault().getLanguage().equals("fr")) {
     yourYesResponse = "C\'est bon " + usersName + "!";
 }

But even if my device is set to French it still displays the English. Is there anything wrong with this if statement and if yes, then what?

EDIT: Thanks for the help. I appreciate it.

like image 747
Mishil D. Avatar asked Oct 19 '14 12:10

Mishil D.


1 Answers

In order to get the device language, you can use this:

Locale.getDefault().getDisplayLanguage();

or,

Locale.getDefault().getLanguage(); //to get usual language code
like image 126
Tarek Avatar answered Sep 29 '22 15:09

Tarek