From 17d23409467963d87c503707b704f5a84b655d99 Mon Sep 17 00:00:00 2001 From: tisfeng Date: Sun, 17 Dec 2023 22:35:06 +0800 Subject: [PATCH] perf: do not query Chinese dict if text is English words --- Easydict/Feature/Service/Apple/EZAppleService.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Easydict/Feature/Service/Apple/EZAppleService.m b/Easydict/Feature/Service/Apple/EZAppleService.m index 9e3f2f069..e2a4b567c 100644 --- a/Easydict/Feature/Service/Apple/EZAppleService.m +++ b/Easydict/Feature/Service/Apple/EZAppleService.m @@ -505,10 +505,19 @@ - (EZLanguage)detectTextLanguage:(NSString *)text printLog:(BOOL)logFlag { // TODO: Maybe we can use this way to detect other language. - NSArray *needCorrectedLanguages = @[ + NSMutableArray *needCorrectedLanguages = @[ EZLanguageEnglish, // si - EZLanguageSimplifiedChinese, // 浦 - ]; + ].mutableCopy; + + /** + Fix: cuda was detectde as SimplifiedChinese, --> 粗大 cuda + + Apple spell check 'cuda' as English, but sometimes Spanish 🥲 + */ + if (![text isEnglishPhrase]) { + // 浦 was detected as Japanese, we need to correct it. + [needCorrectedLanguages addObject:EZLanguageSimplifiedChinese]; + } BOOL isWordLength = text.length <= EZEnglishWordMaxLength;