How to get application language and device language separately in android?
Asked Answered
A

4

36

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

Any answered 29/3, 2017 at 11:29 Comment(1)
using Locale you could set and app languageAdsorb
P
70

Get system language

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

Get app language

String currentLang = Locale.getDefault().getLanguage();
Prorogue answered 29/3, 2017 at 11:38 Comment(3)
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.Treed
Resources.getSystem().getConfiguration().locale.getLanguage() is deprecatedEmpery
if the language is english, does it return 'English' or 'en'?Viola
C
8

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")
Carillon answered 29/10, 2019 at 16:0 Comment(0)
P
7

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

Propane answered 5/10, 2018 at 10:15 Comment(0)
O
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();
Otranto answered 26/6, 2019 at 13:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.