35

My device language is in English and my application language is in Italian.So how I get the device language and application language programmatically ?

mob_web_dev
  • 2,342
  • 1
  • 20
  • 42

4 Answers4

69

Get system language

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

Get app language

String currentLang = Locale.getDefault().getLanguage();
VelocityPulse
  • 613
  • 7
  • 13
Elsunhoty
  • 1,609
  • 14
  • 27
  • 7
    What do you mean by "get app language"? In case the system is set to a language not supported by the app, both will return the system language, even though the app displays in a different language. – arekolek Feb 12 '19 at 21:58
  • 2
    Resources.getSystem().getConfiguration().locale.getLanguage() is deprecated – Agna JirKon Rx Sep 03 '19 at 12:53
  • 1
    if the language is english, does it return 'English' or 'en'? – Ahmed Rajab Nov 29 '20 at 17:58
7

This is the correct answer: getResources().getConfiguration().locale

Ahmad Shahwaiz
  • 1,432
  • 1
  • 17
  • 35
7

To Get System Language Use this:

String DeviceLang =Resources.getSystem().getConfiguration().locale.getLanguage();

And For the Application Language Use this:

String AppLang = Resources.getConfiguration().locale.getLanguage();
7

Kotlin - Android X:

val currentSysLocale = Resources.getSystem().getConfiguration().locales[0]
val currentAppLocale = Locale.getDefault().getLanguage()
Log.d("sys locale","$currentSysLocale")
Log.d("app locale","$currentAppLocale")
Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133