I have an app that can be used in either the default Locale (english) or French.
I am using Android's per-app's language feature to allow the user to change the language in the app itself.
Below in my code:
Settings.kt (This is how the language is applied in settings)
AppCompatDelegate.setApplicationLocales(
if(it.lowercase() == KEYWORD_LOCALE_DEFAULT){
Log.i(TAG, "Setting default locale")
LocaleListCompat.getEmptyLocaleList()
}else{
Log.i(TAG, "Setting locale: $it")
LocaleListCompat.forLanguageTags(it)
}
)
I am then adding a log in the MainActivity
to check if it's working
MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.i(
TAG, "Starting app with local system ${
getSystemService(
LocaleManager::class.java
).applicationLocales
}"
)
Log.i(
TAG, "Starting app with app compat ${
AppCompatDelegate.getApplicationLocales()
}"
)
As expected, it is logging fine as below:
Starting app with local system []
Starting app with app compat []
// After changing settings
Starting app with local system [fr]
Starting app with app compat [fr]
This issue is the strings are not changing in the app.
I have defined 3 strings file as shown below but the strings are not working
strings.xml (fr)
<string name="headline_home_primary">Change to French Test</string>
<string name="headline_home_secondary">Change to French Test</string>
<string name="headline_home_tertiary">Change to French Test</string>
<string name="headline_home_quaternary">Change to French Test</string>
strings.xml
<string name="headline_home_primary">Change to Engl Test</string>
<string name="headline_home_secondary">Change to English Test</string>
<string name="headline_home_tertiary">Change to English Test</string>
<string name="headline_home_quaternary">Change to English Test</string>
I am using Jetpack Compose for my UI and the below are my settings
minSdk 29
targetSdk 33
Also i ran the app on the following devices:
Emulator
- Pixel 5 (API 30)
- Pixel 7 (API 33)
Physical
- Pixel 7 (Android 13 - API 33)
Nothing works. Can someone please help out?