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

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


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.


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

Example

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

Result

My locale::English


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

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