Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current language in Android?

Tags:

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 ?

like image 292
Wun Avatar asked Jul 21 '17 08:07

Wun


People also ask

How do I find my Android device language?

This example demonstrate about how to Get the current language in Android device. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I change my local language on 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.

What is Locale default Android?

The default Locale is constructed statically at runtime for your application process from the system property settings, so it will represent the Locale selected on that device when the application was launched.


2 Answers

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.

like image 160
Prexx Avatar answered Oct 01 '22 04:10

Prexx


if you check Locale.UK in code it is en_GB

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

like image 35
Pratik Popat Avatar answered Oct 01 '22 04:10

Pratik Popat