Search code examples
androidandroid-13

Why is per app language not working with application context on pre Android 13


I am trying to implement the per app language feature that was introduced in Android 13. I am using AppCompatDelegate.setApplicationLocales and it's working very well on Android 13. On Android 12 it's working if I use activity context but not application context. The following snippet from an activity produces different output on Android 12.

Log.d(TAG, applicationContext.getString(R.string.settings_change_button))
Log.d(TAG, getString(R.string.settings_change_button))

First line is printed in phone language and second in line is printed in app language. I added the AppLocalesMetadataHolderService as it is shown here https://developer.android.com/guide/topics/resources/app-languages#android12-impl

Should I do something else to get the application context to use the app language?


Solution

  • Unfortunately this seems to be the intended behavior which renders this feature to be useless for me. https://issuetracker.google.com/issues/243457462#comment2

    Edit: Fixed in https://developer.android.com/jetpack/androidx/releases/core#1.11.0 if you use ContextCompat.getContextForLanguage(applicationContext) instead of applicationContext directly. https://developer.android.com/reference/androidx/core/content/ContextCompat#getContextForLanguage(android.content.Context)