Reputation: 16015
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?
Upvotes: 16
Views: 22069
Reputation: 11
Locale.getDefault().getDisplayLanguage();
if(Locale.getDefault().getDisplayLanguage().equals("English")){
//do something
}
Upvotes: 0
Reputation: 11
All I can say about language is that :
1- in order to get the current language of app itself you should use
String CurrentLang = getResources().getConfiguration().locale.getLanguage();
2- in order to get the current language of the device you should use
String CurrentLang = Locale.getDefault().getLanguage();
Upvotes: 1
Reputation: 3708
To know if the default language is an english variant (en_GB or en_AU or en_IN or en_US) then try this
if (Locale.getDefault().getLanguage().equals(new Locale("en").getLanguage())) {
Log.d(TAG, "Language is English");
}
Upvotes: 0
Reputation: 14659
The proper way is probably:
boolean def_english = Locale.getDefault().getISO3Language().equals(Locale.ENGLISH.getISO3Language());
Upvotes: 2
Reputation: 5375
What about using Java's startsWith() function to check whether the current locale is an English variant or not.
Locale.getDefault().getLanguage().startsWith("en")
Upvotes: 5
Reputation: 36302
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.
Upvotes: 28
Reputation: 5825
An alternative solution would be to create a localized English version of the form. See http://developer.android.com/guide/topics/resources/localization.html for details.
Upvotes: 2
Reputation: 53657
Locale.getDefault().getDisplayLanguage() will give your default language of your device
System.out.println("My locale::"+Locale.getDefault().getDisplayLanguage());
My locale::English
Upvotes: 15