Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facing issue on changing App Language in Android 13 & 14

I set my android app local via

fun setSystemLocale(context: Context): Context {
        val locale = getCurrentLanguage().locale
        Locale.setDefault(locale)
        val configuration = Configuration(context.resources.configuration)
        configuration.setLocale(locale)
        configuration.setLayoutDirection(locale)
        context.resources.updateConfiguration(configuration, context.resources.displayMetrics)
        return context.createConfigurationContext(configuration)
    }

set app local work fine on lower versions(Below Android 13) but, on Android 13 & 14 Sometimes language change partially or sometimes language change does not reflect.

like image 302
Shashank Tyagi Avatar asked Oct 16 '25 20:10

Shashank Tyagi


1 Answers

Sometimes language is changed partially in Android 13 & 14.

I could find a solution in android's developer doc.

Here is a sample code.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    val appLocale = when (languageCode) {
        "firstCode" -> LocaleListCompat.forLanguageTags("en")
        "secondCode" -> LocaleListCompat.forLanguageTags("ar")
    }
    // Call this on the main thread as it may require Activity.restart()
    AppCompatDelegate.setApplicationLocales(appLocale)
}                            

If you want to use this solution, your appcompat version must be 1.6.0 or higher.

like image 71
Taein Avatar answered Oct 19 '25 11:10

Taein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!