Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to change language for appcompat:1.2.0-rc02 #15

Closed
al-tush opened this issue Jul 24, 2020 · 25 comments
Closed

failed to change language for appcompat:1.2.0-rc02 #15

al-tush opened this issue Jul 24, 2020 · 25 comments

Comments

@al-tush
Copy link

al-tush commented Jul 24, 2020

Failed to change language for version 1.2.0-rc02 (and rc01) of androidx.appcompat:appcompat.
It is important because androidx.appcompat:appcompat:1.1.0 have some major issues (like highcharts/highcharts-android#115 ) with old Android versions.

@al-tush al-tush changed the title failed to restore non-OS language on app start for appcompat:1.2.0-rc01 failed to change language on app start for appcompat:1.2.0-rc02 Jul 24, 2020
@al-tush al-tush changed the title failed to change language on app start for appcompat:1.2.0-rc02 failed to change language for appcompat:1.2.0-rc02 Jul 24, 2020
@al-tush
Copy link
Author

al-tush commented Jul 24, 2020

Check https://github.com/akexorcist/Localization/tree/1.2.5 - it works ok

@gunhansancar
Copy link
Member

gunhansancar commented Jul 28, 2020

Thanks for your report. I tried with 1.2.0-rc02 and it works.

Could you tell me what version of the library you're using?
What's the OS version of the device?

Please try to use version 1.0.4 as it should work with all appcompat versions.
But regardless the android team makes breaking changes in the appcompat library a lot so It is better to support just official releases instead of alpha, beta, or rc versions.

@al-tush
Copy link
Author

al-tush commented Jul 28, 2020

I check it on 1.0.4 on Android 9 (API 28) and the bug reproduces only when app starts.
It's ok to wait stable appcompat version and then retest the bug. Thank you!

@gunhansancar
Copy link
Member

What exactly not working on app start? Did you apply all of the necessary steps? It should be working fine.

al-tush pushed a commit to al-tush/locale-helper-android-test that referenced this issue Jul 29, 2020
@al-tush
Copy link
Author

al-tush commented Jul 29, 2020

Here is a test: https://github.com/altush1983/locale-helper-android-test
Test case is:

  1. run app and press "Switch to Russian" (it works good)
  2. close app and restart it. Language is english (it is wrong)

It works ok if replace
implementation 'androidx.appcompat:appcompat:1.2.0-rc02'
to
implementation 'androidx.appcompat:appcompat:1.1.0'

Test it on emulator:

AvdId = Pixel_2_API_28
PlayStore.enabled = true
abi.type = x86_64
avd.ini.displayname = Pixel 2 API 28
avd.ini.encoding = UTF-8
disk.dataPartition.size = 6442450944
fastboot.chosenSnapshotFile = 
fastboot.forceChosenSnapshotBoot = no
fastboot.forceColdBoot = no
fastboot.forceFastBoot = yes
hw.accelerometer = yes
hw.arc = false
hw.audioInput = yes
hw.battery = yes
hw.camera.back = virtualscene
hw.camera.front = emulated
hw.cpu.arch = x86_64
hw.cpu.ncore = 4
hw.dPad = no
hw.device.hash2 = MD5:55acbc835978f326788ed66a5cd4c9a7
hw.device.manufacturer = Google
hw.device.name = pixel_2
hw.gps = yes
hw.gpu.enabled = yes
hw.gpu.mode = auto
hw.initialOrientation = Portrait
hw.keyboard = yes
hw.lcd.density = 420
hw.lcd.height = 1920
hw.lcd.width = 1080
hw.mainKeys = no
hw.ramSize = 1536
hw.sdCard = yes
hw.sensors.orientation = yes
hw.sensors.proximity = yes
hw.trackBall = no
image.sysdir.1 = system-images/android-28/google_apis_playstore/x86_64/
runtime.network.latency = none
runtime.network.speed = full
sdcard.size = 512M
showDeviceFrame = yes
skin.dynamic = yes
skin.name = pixel_2
skin.path = /Users/altush/Library/Android/sdk/skins/pixel_2
tag.display = Google Play
tag.id = google_apis_playstore
vm.heapSize = 256

@gunhansancar
Copy link
Member

gunhansancar commented Jul 29, 2020

Yes, you're right. 1.2.0-rc02 causing a lot of problems.
I also checked out the library you shared I noticed the same problem.

Also I noticed that when you don't use LocaleAwareApplication it works somehow correctly but I'm sure it will break for some other Android API Level or some configuration changes.

@al-tush
Copy link
Author

al-tush commented Jul 29, 2020

@gunhansancar
Copy link
Member

I pulled the latest changes in your test repo and it doesn't work after the first run.

@KORuL
Copy link

KORuL commented Aug 13, 2020

I have same problem? please help

@gunhansancar
Copy link
Member

Let's focus on stable releases

@thereisonlywe
Copy link

thereisonlywe commented Aug 16, 2020

Same problem applies to appcompat stable release as well. When the app is first created, language setting is retrieved but the views can't benefit from it. Resuming after home button click doesn't affect the situation, but restarting activity after exiting the app with the back key solves it. Triggering a rebirth also does the job.

@gunhansancar
Copy link
Member

@thereisonlywe I don't observe it on the example app that is shared on this repo. Which stable version do you use? And can you test with the example app?

@beeshop-daniel
Copy link

appcompat 1.2.0 released. but it's not working properly with the helper.

@gunhansancar
Copy link
Member

Working on a fix which would fix any issues for 1.2.0 and later versions.

@gunhansancar
Copy link
Member

Published a version 1.1.0-beta1 I tried with different Android API levels and seems working fine but please let me know if you have any issues.

  • Removed LocaleAwareApplication class
  • Removed LocaleHelperApplicationDelegate class
  • Updated androidx.appcompat:appcompat to 1.2.0

@beeshop-daniel
Copy link

still has issues. application context didn't get changed after switching locale. i also have issues switching between zh_CN and zh_TW. my app has en, zh_cn, zh_tw, only en and zh_cn work after upgrading.

@gunhansancar
Copy link
Member

@beeshop-daniel can you share a sample app so that I can work on it to solve the problem?

@beeshop-daniel
Copy link

@beeshop-daniel can you share a sample app so that I can work on it to solve the problem?

i will try to create a quick sample app for u.

@alexeyvasilyev
Copy link

Works perfectly on Android 11 Beta with appcompat 1.2.0 and 1.1.0-beta1

@shiSHARK
Copy link

shiSHARK commented Sep 8, 2020

Hey mates. I also have this problem and I also found this sample to work just fine - https://josipsalkovic.com/2020/05/01/changing-locale-uimode-runtime-android/

What I think is the key here is these lines of code:

this method is simplified but works perfectly

fun changeLocaleOnAttachBaseContext(context: Context):Context {
    val locale = PreferencesUtils.getLocale(base)
    Locale.setDefault(locale)
    val res = context.resources
    val config = Configuration(res?.configuration)
    config.setLocale(locale)
    return context.createConfigurationContext(config)
}

@gunhansancar
Copy link
Member

@shiSHARK There are a lot of combinations going on like Android version, appcompat version etc. Have you really tested with API level 16 to 29 and with different app compat versions?

Please also check it out 1.1.0-beta1 of LocaleHelper

@shiSHARK
Copy link

shiSHARK commented Sep 9, 2020

I have tested on 24 to 29 - these are the version we use and also only on androidx.appcompat:appcompat:1.2.0
But i believe that will work for most, if not all people.

@alexeyvasilyev
Copy link

alexeyvasilyev commented Sep 12, 2020

locale-helper-android: 1.1.0-beta1
androidX AppCompat: 1.2.0

Android 11 - works.
Android 10 - does not work.
Android 9 - works.
Android 8.1 - works.
Android 7.1.1 - does not work (tested on two different Google Nexus devices)
Android 6.0.1 - works.
Android 5.1.1 - works.

gunhansancar added a commit that referenced this issue Sep 21, 2020
gunhansancar added a commit that referenced this issue Sep 21, 2020
* Solving the problems in #15

* Optimisation

* Update dependencies
@gunhansancar
Copy link
Member

gunhansancar commented Sep 21, 2020

Published a version 1.1.0-beta2 which works in all versions also support Dark Mode with androidx.appcompat 1.2.0 is used.

  • Reintroduced the LocaleAwareApplication or LocaleHelperApplicationDelegate as it is mandatory to make some versions to work
  • Instead of using LocaleAwareCompatActivity if you're using LocaleHelperActivityDelegate directly please also override the following methods: getDelegate and createConfigurationContext for more details check LocaleHelperActivities class

If anyone can test the beta version, I will publish the 1.1.0 soon after that.

Note: The versions that I tested with are the following:
API 19 K 4.4 Working
API 22 L 5.1 Working
API 23 M 6 Working
API 24 N 7.0 Working
API 25 N 7.1 Working
API 26 O 8.0 Working
API 27 O 8.1 Working
API 28 P 9 Working
API 29 10 Working
API 30 11 Working

Thanks.

@gunhansancar
Copy link
Member

Released 1.1.0 which seems to work for all version when using appcompat 1.2.0. If you encounter any issues please reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants