Wun
Wun

Reputation: 6381

How to get the current language in Android?

In my Android phone language setting, I set the language to the English(United Kingdowm).

And I use the following code to get the language:

Log.d(TAG,"getDisplayLanguage = " + Locale.getDefault().getDisplayLanguage());
Log.d(TAG,"getLanguage = " + Locale.getDefault().getLanguage());
Log.d(TAG,"Resources.getLanguage = " + Resources.getSystem().getConfiguration().locale.getLanguage());
Log.d(TAG,"getResources.getLanguage = " + getResources().getConfiguration().locale);

And the log show like the following:

getDisplayLanguage = English
getLanguage = en
Resources.getLanguage = en
getResources.getLanguage = en_GB

It did not show Local.UK.

Did I missing something ?

Upvotes: 5

Views: 6649

Answers (3)

Arnab Kundu
Arnab Kundu

Reputation: 1527

It wouldn't return like that what try you trying to get in Log massage. Log massage will print only string value. But Locale is a class and UK is(public static final Locale UK = null;) a variable in the class. which return the same string value u r getting in Log massage.

Upvotes: 1

Pratik Popat
Pratik Popat

Reputation: 2999

if you check Locale.UK in code it is en_GB

http://www.localeplanet.com/icu/en-GB/

Upvotes: 1

Prexx
Prexx

Reputation: 2979

According to the answer in Is en_UK an illegal locale?

The correct country code is en_GB. Locales use ISO 3166-1 for country codes. The wikipedia writeup includes:

The codes are chosen, according to the ISO 3166/MA, "to reflect the significant, unique component of the country name in order to allow a visual association between country name and country code".[7] For this reason, common components of country names like "Republic", "Kingdom", "United", "Federal" or "Democratic" are normally not used for deriving the code elements. As a consequence, for example, the United Kingdom is officially assigned the alpha-2 code GB rather than UK, based on its official name "United Kingdom of Great Britain and Northern Ireland" (although UK is reserved on the request of the United Kingdom).

Thats not my answer, it's the answer from the linked post. Just in case the linked answer won't be available at some time.

Upvotes: 2

Related Questions