YarikSOffice / lingver

Manage your application locale and language.
https://proandroiddev.com/change-language-programmatically-at-runtime-on-android-5e6bc15c758
MIT License
512 stars 61 forks source link

Locale not working proper in Android 11 and Android 12 #52

Open yahya-ebizz opened 2 years ago

YarikSOffice commented 2 years ago

Hey @yahya-ebizz

Could you please share more details on what is wrong with Android 11 and 12?

I've tested the sample app using the latest versions, but I haven't come across any issues.

zeroDivider commented 1 year ago

I spotted it is not working on Android 13 ether. It is translating half of the app, also changing language 2 or more times when app is active is especially critical..

ahmed-elkhadragy commented 1 year ago

the library works great on Android 10, but when tested on Android 12 I found that words do translate to the right language but layout don't change direction ltr to rtl and vise versa

YarikSOffice commented 1 year ago

@zeroDivider @ahmed-elkhadragy Trying to figure out what is the cause of your issue with new android versions

  1. Do you restart your activity/app once the new locale is applied?
  2. Do you use the navigation component/fragments for your screens?
ahmed-elkhadragy commented 1 year ago

@zeroDivider @ahmed-elkhadragy Trying to figure out what is the cause of your issue with new android versions

  1. Do you restart your activity/app once the new locale is applied?
  2. Do you use the navigation component/fragments for your screens?

Hello, yes I used receeate() to restart the activity and it indded changes language but it's all about layout direction and I don't use navigation component nor fragment my app is single screen single activity app.. I turned around the issue right now until it's figured out by making the locale change in different activity and reopening the original activity and it works fine but my original plan was to change locale from the same screen/activity

AlexeyGodyaev commented 1 year ago

reason: IME_AUTOFILL_DEFAULT_SUPPORTED_LOCALES_IS_EMPTY Change ID: 169273070 Default State: Enabled for apps that target Android 12 (API level 31) or higher. For apps targeting Android 12 (API level 31) and higher, [getSupportedLocales()](https://developer.android.com/reference/android/view/inputmethod/InlineSuggestionsRequest#getSupportedLocales()) now returns an empty locale list when it's not set, instead of the default system locale.

PS: Just passing by, due to an attempt to migrate from Sharedpreferences to DataStore

AlexeyGodyaev commented 1 year ago

My option fun Configuration.getFirstLocale(): Locale = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { getSystemLocale() } else { val locales = ConfigurationCompat.getLocales(this) if (locales.isEmpty) localeENGLISH else (locales[0] ?: localeENGLISH) }

fun getSystemLocale(): Locale = getSystemLocales().get(0) ?: Locale.getDefault() fun getSystemLocales(): LocaleListCompat = ConfigurationCompat.getLocales(Resources.getSystem().configuration)