Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if the language is English (All variants) on Android?

Tags:

android

locale

I want to show a button only for English users, is there a way to detect the language settings?

I know how to get the current Locale, but I don't know if comparing it against Locale.English is sufficient, since there must be a lot of English variations etc.

Anyone experience doing this?

like image 605
Peterdk Avatar asked Jun 16 '11 07:06

Peterdk


People also ask

How do I check my language on Android?

You can use Locale. getDefault(). getLanguage(); to get the usual language code (e.g. "de", "en").

How do I change the whole app language in Android?

Go to app > res > values > right-click > New > Value Resource File and name it as strings. Now, we have to choose qualifiers as Locale from the available list and select the language as Hindi from the drop-down list. Below is the picture of the steps to be performed.


3 Answers

From the Locale docs:

The language codes are two-letter lowercase ISO language codes (such as "en") as defined by ISO 639-1. The country codes are two-letter uppercase ISO country codes (such as "US") as defined by ISO 3166-1.

This means that

Locale.getDefault().getLanguage().equals("en")

should be true. I'd be careful with hiding/showing UI only by default Locale though. Many countries may have many users that prefer another language, but are perfectly fluent in English.

like image 71
kabuko Avatar answered Oct 16 '22 21:10

kabuko


Locale.getDefault().getDisplayLanguage() will give your default language of your device

Example

System.out.println("My locale::"+Locale.getDefault().getDisplayLanguage());

Result

My locale::English

like image 25
Sunil Kumar Sahoo Avatar answered Oct 16 '22 20:10

Sunil Kumar Sahoo


What about using Java's startsWith() function to check whether the current locale is an English variant or not.

Locale.getDefault().getLanguage().startsWith("en")
like image 31
blizzard Avatar answered Oct 16 '22 19:10

blizzard