3

How to programatically find the language the app is using. For example the device Locale is set to es_MX but my app supports only en_US and hence the app displays text only in English.

How to programatically find that app is using English and not Spanish in this case?

All the below code returns ex_MX

    Locale locale = getResources().getConfiguration().getLocales().get(0);
    Locale l = Resources.getSystem().getConfiguration().getLocales().get(0);
    Locale l1 = Locale.getDefault();

2 Answers2

0

Please Refer this given link's answer as you must get locale at the time of starting the app. If you will set your locale once in whole life cycle, you will get only the language as default as you set in the locale.

https://stackoverflow.com/a/23556454/6549856

Chintak Patel
  • 748
  • 6
  • 24
  • My use case is different. The app is not setting any locale and it merely uses the Locale set on the device. But if a locale not supported by the app is set, the app will default to the closest language (es instead of es_MX). How can we know which language the app is using currently. – Prabhu Swaminathan Mar 02 '18 at 12:17
0

You can get the system language.

Resources.getSystem().getConfiguration().locale.getLanguage();

for app default language

String CurrentLanguage = Locale.getDefault().getLanguage();
Fazal Hussain
  • 1,129
  • 12
  • 28
  • In my case both the method will return Language as es_MX which is set in the device. But since my app doesn't support es_MX and supports only es, the app will be using es. – Prabhu Swaminathan Mar 02 '18 at 12:15
  • https://www.google.com.pk/url?sa=t&source=web&rct=j&url=https://stackoverflow.com/questions/43092248/how-to-get-application-language-and-device-language-separately-in-android/43092407&ved=2ahUKEwjH14j9-83ZAhUM26QKHUouBR8QFjABegQIAxAB&usg=AOvVaw2r4nah2RW6_6OXB6UwUfGZ – Fazal Hussain Mar 02 '18 at 15:39