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

🐞 Bug Report: App language does not change after update language orders in system settings #305

Closed
5 tasks done
phlpsong opened this issue Jan 5, 2024 · 8 comments
Closed
5 tasks done
Assignees
Labels
bug Something isn't working fixed in next release The issue will be closed once next release is available

Comments

@phlpsong
Copy link
Collaborator

phlpsong commented Jan 5, 2024

Please confirm the following:

  • I have carefully read the README
  • I have searched through the issues page but couldn't find a solution.(Including issue that has been closed)
  • Easydict has been upgraded to the latest version
  • I understand and agree to the above, and understand that the project maintainer has limited energy, issues that do not follow the rules may be ignored or closed directly

Problem description

App language does not change after updating language orders in system settings.

You can check the screenshot attached below.
After changing preferred languages to (1. 简体中文 2. English) in System Settings, the result from [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] in app is

[
  "en-CN",
  "zh-Hans-CN"
]

but in the terminal the result is

(
    "zh-Hans-CN",
    "en-CN"
)

Reproduction steps

  1. Go to System Settings -> General -> Languages and regions -> Preferred Languages
  2. Update language order, like swap English and 简体中文
  3. Rebot(Optional) and relaunch app
  4. Check app language

Screenshot

截屏2024-01-05 11 24 52

Expected result

App language follows system settings

Proposed solution (optional)

No response

Device type and OS version

MacOS 14.2.1, Easydict 2.5.0

Are you willing to submit a PR to fix this issue?

  • I'm willing to submit a PR
@phlpsong phlpsong added the bug Something isn't working label Jan 5, 2024
@phlpsong
Copy link
Collaborator Author

phlpsong commented Jan 5, 2024

After debugging I found AppleLanguages values are not updated after the system languages change.

A similar issue in https://stackoverflow.com/questions/24841113/override-applelanguages-in-nsuserdefaults ,

if I insert a new object at index 0 and later on change the system language, iOS will not put the new language on the top of the list anymore. 

which is pretty like what we do in AppDelegate.

@tisfeng appreciate it if you could confirm it.

@tisfeng
Copy link
Owner

tisfeng commented Jan 5, 2024

使用 [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] 方式获取系统语言并不好,遇到特殊语言,如 Canadian English 会导致语言解析有问题。后面我改成了 [NSLocale preferredLanguages]

!!!: For Canadian English, AppleLanguages returns "en_CA", while [NSLocale preferredLanguages] returns "en-CA"

另外,一般我们也没必要修改 AppleLanguages,之前我修改这个值是为了测试,后面忘记移除了。

具体你可以看 localization 分支的这个提交 e8923f0

@phlpsong
Copy link
Collaborator Author

phlpsong commented Jan 5, 2024

Yes, I think the AppleLanguages result combines the language and region, such as en_CN, and currently we using en_CN and zh-CN to update its values in AppDelegate is not accurate if users are in other regions.

另外,一般我们也没必要修改 AppleLanguages,之前我修改这个值是为了测试,后面忘记移除了。

Yeah, we should not update this. After removing setupAppLanguage the behavior is fine.

Do you have a plan to merge the commit into dev or apply a new commit to fix this?

@tisfeng
Copy link
Owner

tisfeng commented Jan 5, 2024

你测一下看这个提交 e8923f0 会有你说的问题吗? 如果没问题,稍后我就把它 pick 过来。

@phlpsong
Copy link
Collaborator Author

phlpsong commented Jan 5, 2024

I tested but it's not working as expected.

I think the reason is the app has changed the AppleLanguages values which will prevent it refresh after system changes.

A workaround is to reset this value when EZLanguageManager setup.

@tisfeng
Copy link
Owner

tisfeng commented Jan 5, 2024

行,那麻烦你修复一下这个问题,可以把 e8923f0 pick 过去,弄个新 PR。

@tisfeng tisfeng added the fixed in next release The issue will be closed once next release is available label Jan 5, 2024
@phlpsong
Copy link
Collaborator Author

phlpsong commented Jan 5, 2024

Sure, will create one later.

phlpsong added a commit to phlpsong/Easydict that referenced this issue Jan 5, 2024
tisfeng added a commit that referenced this issue Jan 5, 2024
…306)

* perf: use NSLocale.preferredLanguages instead of NSUserDefaults AppleLanguages

* bugfix: #305 reset AppleLanguages values

---------

Co-authored-by: tisfeng <[email protected]>
tisfeng added a commit that referenced this issue Jan 6, 2024
…306)

* perf: use NSLocale.preferredLanguages instead of NSUserDefaults AppleLanguages

* bugfix: #305 reset AppleLanguages values

---------

Co-authored-by: tisfeng <[email protected]>
tisfeng added a commit that referenced this issue Jan 6, 2024
…306)

* perf: use NSLocale.preferredLanguages instead of NSUserDefaults AppleLanguages

* bugfix: #305 reset AppleLanguages values

---------

Co-authored-by: tisfeng <[email protected]>
@tisfeng
Copy link
Owner

tisfeng commented Feb 9, 2024

2.6.0 新版本已修复该问题。

@tisfeng tisfeng closed this as completed Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next release The issue will be closed once next release is available
Projects
None yet
Development

No branches or pull requests

2 participants