tisfeng / Easydict

一个简洁优雅的词典翻译 macOS App。开箱即用,支持离线 OCR 识别,支持有道词典,🍎 苹果系统词典,🍎 苹果系统翻译,OpenAI,Gemini,DeepL,Google,Bing,腾讯,百度,阿里,小牛,彩云和火山翻译。A concise and elegant Dictionary and Translator macOS App for looking up words and translating text.
GNU General Public License v3.0
7.03k stars 356 forks source link

🐞 Bug Report: Apple Dict doesn't work in some languages #677

Open windrunner414 opened 2 weeks ago

windrunner414 commented 2 weeks ago

Please confirm the following:

Problem description

Apple Dict in Easydict returns no result when the query text contains hiragana/katakana (Japanese) or some Swedish letters (å, ä, ö). I only tested Japanese and Swedish, it's possible that all characters other than Chinese and Latin don't work. For example, はなし: 超級クラウン中日辞典 / クラウン日中辞典 (the built-in one in apple dictionary):

Screenshot 2024-09-16 at 3 45 49 AM

Easydict:

Screenshot 2024-09-16 at 3 46 21 AM

However, 話 will return the correct results

Screenshot 2024-09-16 at 3 48 15 AM

Is the issue consistently reproducible?

Reproducible

Steps to Reproduce

  1. Enabling 超級クラウン中日辞典 / クラウン日中辞典 in Apple Dictionary
  2. Quering any word contains hiragana, e.g. はなし. Apple Dictionary will show the correct result but Easydict will say no result

Screenshot

Screenshot 2024-09-16 at 3 46 21 AM

Runtime log(zip file)

Sorry there are too many menu icons on my laptop and the easydict one is not showing up, I'll try to get the log later

Expected result

Easydict shows the correct result as Apple Dictionary does

Proposed solution (optional)

No response

Device type and OS version

Apple M1 Pro, MacOS 14.6.1

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

github-actions[bot] commented 2 weeks ago

Hello windrunner414, Thank you for your first issue contribution 🎉

windrunner414 commented 2 weeks ago

Just had a look into code. Maybe it doesn't even query the dictionary because word count > 1 https://github.com/tisfeng/Easydict/blob/main/Easydict/objc/Service/Apple/AppleDictionary/EZAppleDictionary.m#L126 https://github.com/tisfeng/Easydict/blob/2d0cf752df5fd3e7f31e5752409c801744d83f2a/Easydict/objc/Utility/EZCategory/NSString/NSString%2BEZUtils.m#L174

It appears Chinese bypasses the word count check in shouldQueryDictionaryWithLanguage so it works for Chinese. Not sure why Swedish "välkommen" also returns no result, maybe the word count is not accurate for Swedish?

I don't have a dev environment to debug it now, I probably can take a closer look some time later though. It may be better to have a setting allowing it to always query in dictionary?

tisfeng commented 2 weeks ago

ok, I'll take a look at it later.

tisfeng commented 2 weeks ago

This is a bug.

The Apple dictionary query should not call the queryTypeWithLanguage method here because this method is incomplete. Initially, I only considered Chinese and English, and it is not suitable for other languages, such as Japanese.

I have removed this check https://github.com/tisfeng/Easydict/pull/681, and the next version will fix it.