birchill / 10ten-ja-reader

A browser extension to translate Japanese by hovering over words.
https://addons.mozilla.org/firefox/addon/10ten-ja-reader/
GNU General Public License v3.0
605 stars 45 forks source link

zh_hans locale not working #2051

Closed ph0ngp closed 3 weeks ago

ph0ngp commented 3 weeks ago

When I set the system language to Simplified Chinese, I still see all the UI texts in English. I have tested on Chrome (macOS), Safari (macOS), Safari (iOS). They all have this behavior. Somehow the locale zh_hans is not detected. When I set the system language to Japanese, they all work normally (displaying Japanese UI text).

birtles commented 3 weeks ago

Hi!

I just tried this with Chrome on Windows and it looks like you can't set the language to zh-hans only zh-CN? This page seems to confirm that.

I guess Firefox allows zh_hans though since I believe this localization is working for @SaltfishAmi.

I'll need to test if renaming the folder to zh_CN continues working with Firefox (and also fixes Chrome and Safari).

SaltfishAmi commented 3 weeks ago

I never tested the localization for the previous two years, since I cannot change language for the extension only, and I do not personally use chinese interface for other parts of my computer. sorry...

It worked when I first added it many years ago.

birtles commented 3 weeks ago

I've made up a PR to fix this in Chrome at least and I've verified that it doesn't break Firefox. (I'm not sure if it was actually broken in Firefox to begin with because the original approach I used for testing turned out to be wrong.)

However, it won't fix Safari because it looks like Safari doesn't handle language subtags correctly: https://forums.developer.apple.com/forums/thread/762697 (see also https://github.com/adobe/helix-sidekick-extension/issues/721) despite the discussion here indicating Safari does handle subtags.

xeenon commented 3 weeks ago

@birtles With this change, I'm seeing zh_CN being loaded and used in Safari 18 for your extension. We look for zh_CN, zh, then en (default_locale).

birtles commented 3 weeks ago

@birtles With this change, I'm seeing zh_CN being loaded and used in Safari 18 for your extension. We look for zh_CN, zh, then en (default_locale).

@xeenon thank you so much for checking! I tried this yesterday on Safari 18.0.1 on my Mac and it failed to show the zh_CN locale in the settings page although Japanese worked fine. I won't be near a Mac for a few days but I'll take a screen recording next time I am.

xeenon commented 3 weeks ago

@birtles Make sure you also change your Region to "China mainland", otherwise it will try zh_JP or whatever region you are in currently. Japanese likely worked since it is just ja.

xeenon commented 3 weeks ago

@birtles I found that we can improve this, as setting the region to "China mainland" or "Taiwan" shouldn't be required. I’ve submitted a fix with new tests and error handling. Thanks for bringing this up!

birtles commented 3 weeks ago

@birtles I found that we can improve this, as setting the region to "China mainland" or "Taiwan" shouldn't be required. I’ve submitted a fix with new tests and error handling. Thanks for bringing this up!

@xeenon Thank you! You're amazing. That's perfect. I was confused because the Safari interface changed after updating the language (but not the region) whilst the extension interface did not. Not having the change the region would make the extension interface consistent with the Safari interface.

xeenon commented 3 weeks ago

@birtles My fix also makes zh_hans and zh_hant work if used in _locales too. You might want to open a WECG issue and / or Chrome bug report about zh_hans not working in Chrome.

birtles commented 2 weeks ago

@birtles My fix also makes zh_hans and zh_hant work if used in _locales too. You might want to open a WECG issue and / or Chrome bug report about zh_hans not working in Chrome.

Thanks! I filed Chromium issue 375528194 and updated the WECG thread.