4

I added support per app language to my app, the android 13 feature, now it is both English and Russian. I can change the app language from settings and no need to change the device language. Now for analytics purposes, I need to know the app language and the device language. But if my device is in English and the app is in Russian, I always receive Russian -

   Resources.getSystem().configuration.locales.get(0).language  - ru

   context.resources.configuration.locales[0].language - ru

   Locale.getDefault().language - ru

I expect to receive en from

Resources.getSystem().configuration.locales.get(0).language

and ru from

context.resources.configuration.locales[0].language

I will be glad for any help

Sweta Jain
  • 3,248
  • 6
  • 30
  • 50
Sergey
  • 41
  • 1

2 Answers2

3

The system locale list is available from LocaleManagerCompat.getSystemLocales(Context) in androidx.core:core:1.9.0-beta01 or later.

Ember Rose
  • 31
  • 2
3

I've been working with these:

AppCompatDelegate.getApplicationLocales()  // app locales
LocaleManagerCompat.getSystemLocales(Context) // system locales

getApplicationLocales() may return an empty array [] if there is no app-level setting. In that case, the system locale is being used.

I also use AppCompatDelegate.setApplicationLocales(LocaleListCompat) for consistency.

I'm not sure if there are non-Compat classes available for targeting only API 33, but this is currently working for me down to API 27.

As mentioned in another answer, you'll need to import androidx.appcompat:appcompat:1.6.0-beta01 - see first line here.

aormsby
  • 126
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 27 '22 at 08:05