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

Some strings use the previous language when it is changed in app on API > 24 #8114

Closed
jtreanor opened this issue Jul 27, 2018 · 3 comments · Fixed by #8116 or #10520
Closed

Some strings use the previous language when it is changed in app on API > 24 #8114

jtreanor opened this issue Jul 27, 2018 · 3 comments · Fixed by #8116 or #10520
Assignees

Comments

@jtreanor
Copy link
Contributor

jtreanor commented Jul 27, 2018

Expected behavior

When the language is changed in the app settings, all strings should be in the new language.

Actual behavior

Some strings (most noticeable on the Stats screen) stay in the old language. I encountered this while working on screenshot automation across locales but it also happens in normal usage.

Note that the issue resolves itself on next launch of the app.

Here is a screenshot of the stats screen with mixed language:

screenshot_1532695671

Steps to reproduce the behavior

  1. Open the app on an API version > 24 device/emulator.
  2. Change language via Me -> App Settings.
  3. Go to the stats screen (My Site -> Stats).
  4. The screen will be partially in the original language and partially in the newly chosen language.
Tested on Emulator, Android 24

Worked as expected (stats screen was fully translated).

Tested on Emulator, Android 25

The behaviour was broken as in the screenshot above.

Tested on Emulator, Android 27

Same as version 25.

@jtreanor
Copy link
Contributor Author

jtreanor commented Jul 27, 2018

Background

Due to the deprecation of updateConfiguration(), it is not called on API > 24 in LocaleManager. Instead context.createConfigurationContext() is called which updates the locale throughout the app via attachBaseContext in all Activities and the Application like this:

protected void attachBaseContext(Context base) {
    super.attachBaseContext(LocaleManager.setLocale(base));
}

More detail about this is in the PR which introduced it: #7413.

Cause of the issue

The broken strings are those that are fetched using our static Context with WordPress.getContext().getString(R.string.something). Because mContext in WordPress.java is never updated, locale changes are not reflected by WordPress.getContext().

Possible solutions

  1. Stop using a static Context in WordPress.java. This would solve the issue but I don't suggest a large change should be made just for this. Other issues may necessitate this in future.
  2. Replace every place that we use WordPress.getContext().getString(R.string.something) with some other context. This wouldn't be a huge change but it would leave the underlying issue of an outdated static Context in WordPress.java.
  3. Update mContext in attachBaseContext of WordPress.java. I have tried this approach and attachBaseContext only called on launch at the moment. I feel like it may be possible to get this to work however. Update: Some more research suggests this won't work as attachBaseContext is only called prior to OnCreate.
  4. Update mContext in WordPress.java when the language is changes by exposing a method something like updateContextLocale().

With all of this it is worth noting that I am very new to this codebase so please let me know if I'm way off on any of this 😄

@huaxunhuang
Copy link

huaxunhuang commented Aug 10, 2019

Hi,

I followed the reproduction steps in the latest release of WordPress, but still can find the same problem as stated here. I was wondering if it is related to this issue.

Test device: Huawei P30 Lite, Android 9.0

Steps to reproduce:
(1) the system language is English.
(2) Change language via Me -> App Settings. (I have changed it to Chinese)
(3) Go to the stats screen (My Site -> Stats).
Result: The screen will be partially in the original language and partially in the newly chosen language.

Here is the screenshot you can check.

221565424543_ pic

Thanks a lot for your great work.

@jtreanor
Copy link
Contributor Author

jtreanor commented Aug 12, 2019

Thanks @huaxunhuang, I am reopening this issue. cc @designsimply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment