skip to Main Content

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.

2

Answers


  1. my app has a function to change in-app language too.

    But, I had a same problem in my language picker.

    Sometimes language is changed partially in Android 13 & 14.

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

    https://developer.android.com/guide/topics/resources/app-languages?hl=en#kotlin

    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.

    I hope it works out.

    Login or Signup to reply.
  2. The provided code snippet addresses a potential cause of missing language resources in your app built using Android App Bundles (AAB) for Play Store publishing. Here’s a breakdown of the code and its implications:

    Code Explanation:

    Gradle

    android {
      //... removed for brevity
      bundle {
         language {
           enableSplit = false
         }
       }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search