Skip to content

Commit

Permalink
Merge branch 'dev' into readme-en-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry23011 authored Oct 9, 2023
2 parents 6857688 + e926c16 commit d4851e1
Show file tree
Hide file tree
Showing 17 changed files with 755 additions and 941 deletions.
26 changes: 6 additions & 20 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
033B7134293CE2430096E2DF /* EZWebViewTranslator.m in Sources */ = {isa = PBXBuildFile; fileRef = 033B7133293CE2430096E2DF /* EZWebViewTranslator.m */; };
033C30FC2A7409C40095926A /* TTTDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 033C30FB2A7409C40095926A /* TTTDictionary.m */; };
033C31002A74CECE0095926A /* EZAppleDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 033C30FF2A74CECE0095926A /* EZAppleDictionary.m */; };
034B077329DEBC5800E7FD6B /* EZTextWordUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 034B077229DEBC5800E7FD6B /* EZTextWordUtils.m */; };
03542A30293645DF00C34C33 /* EZAppleService.m in Sources */ = {isa = PBXBuildFile; fileRef = 03542A2F293645DF00C34C33 /* EZAppleService.m */; };
03542A342936F70F00C34C33 /* EZLanguageManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 03542A332936F70F00C34C33 /* EZLanguageManager.m */; };
03542A3A2937AE6400C34C33 /* EZQueryService.m in Sources */ = {isa = PBXBuildFile; fileRef = 03542A392937AE6400C34C33 /* EZQueryService.m */; };
Expand Down Expand Up @@ -195,7 +194,7 @@
03DC7C6A2A3CA852000BF7C9 /* EZAppCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 03DC7C692A3CA852000BF7C9 /* EZAppCell.m */; };
03E02A222924E77100A10260 /* EZMenuItemManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 03E02A212924E77100A10260 /* EZMenuItemManager.m */; };
03E02A2629250D1D00A10260 /* EZEventMonitor.m in Sources */ = {isa = PBXBuildFile; fileRef = 03E02A2529250D1D00A10260 /* EZEventMonitor.m */; };
03E2BF752A298F2B00E010F3 /* NSString+EZCharacterSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 03E2BF742A298F2B00E010F3 /* NSString+EZCharacterSet.m */; };
03E2BF752A298F2B00E010F3 /* NSString+EZUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 03E2BF742A298F2B00E010F3 /* NSString+EZUtils.m */; };
03F0DB382953428300EBF9C1 /* EZLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 03F0DB372953428300EBF9C1 /* EZLog.m */; };
03F14A3B2956016B00CB7379 /* EZVolcanoTranslate.m in Sources */ = {isa = PBXBuildFile; fileRef = 03F14A3A2956016B00CB7379 /* EZVolcanoTranslate.m */; };
03F25CB329327BC200E66A12 /* EZShortcut.m in Sources */ = {isa = PBXBuildFile; fileRef = 03F25CB229327BC200E66A12 /* EZShortcut.m */; };
Expand Down Expand Up @@ -265,8 +264,6 @@
033C30FB2A7409C40095926A /* TTTDictionary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TTTDictionary.m; sourceTree = "<group>"; };
033C30FE2A74CECE0095926A /* EZAppleDictionary.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EZAppleDictionary.h; sourceTree = "<group>"; };
033C30FF2A74CECE0095926A /* EZAppleDictionary.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZAppleDictionary.m; sourceTree = "<group>"; };
034B077129DEBC5800E7FD6B /* EZTextWordUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EZTextWordUtils.h; sourceTree = "<group>"; };
034B077229DEBC5800E7FD6B /* EZTextWordUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZTextWordUtils.m; sourceTree = "<group>"; };
03542A2E293645DF00C34C33 /* EZAppleService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EZAppleService.h; sourceTree = "<group>"; };
03542A2F293645DF00C34C33 /* EZAppleService.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZAppleService.m; sourceTree = "<group>"; };
03542A322936F70F00C34C33 /* EZLanguageManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EZLanguageManager.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -585,8 +582,8 @@
03E02A212924E77100A10260 /* EZMenuItemManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZMenuItemManager.m; sourceTree = "<group>"; };
03E02A2429250D1D00A10260 /* EZEventMonitor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EZEventMonitor.h; sourceTree = "<group>"; };
03E02A2529250D1D00A10260 /* EZEventMonitor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZEventMonitor.m; sourceTree = "<group>"; };
03E2BF732A298F2B00E010F3 /* NSString+EZCharacterSet.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+EZCharacterSet.h"; sourceTree = "<group>"; };
03E2BF742A298F2B00E010F3 /* NSString+EZCharacterSet.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+EZCharacterSet.m"; sourceTree = "<group>"; };
03E2BF732A298F2B00E010F3 /* NSString+EZUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+EZUtils.h"; sourceTree = "<group>"; };
03E2BF742A298F2B00E010F3 /* NSString+EZUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+EZUtils.m"; sourceTree = "<group>"; };
03F0DB362953428300EBF9C1 /* EZLog.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EZLog.h; sourceTree = "<group>"; };
03F0DB372953428300EBF9C1 /* EZLog.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZLog.m; sourceTree = "<group>"; };
03F14A392956016B00CB7379 /* EZVolcanoTranslate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EZVolcanoTranslate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -708,8 +705,8 @@
03BFFC7029612E10004E033E /* NSString+EZConvenience.m */,
0333FDA42A035D5700891515 /* NSString+EZChineseText.h */,
0333FDA52A035D5700891515 /* NSString+EZChineseText.m */,
03E2BF732A298F2B00E010F3 /* NSString+EZCharacterSet.h */,
03E2BF742A298F2B00E010F3 /* NSString+EZCharacterSet.m */,
03E2BF732A298F2B00E010F3 /* NSString+EZUtils.h */,
03E2BF742A298F2B00E010F3 /* NSString+EZUtils.m */,
03D35DA82AA6C49B00B023FE /* NSString+EZRegex.h */,
03D35DA92AA6C49B00B023FE /* NSString+EZRegex.m */,
);
Expand Down Expand Up @@ -756,15 +753,6 @@
path = AppleDictionary;
sourceTree = "<group>";
};
034B077029DEBBFF00E7FD6B /* EZTextWordUtils */ = {
isa = PBXGroup;
children = (
034B077129DEBC5800E7FD6B /* EZTextWordUtils.h */,
034B077229DEBC5800E7FD6B /* EZTextWordUtils.m */,
);
path = EZTextWordUtils;
sourceTree = "<group>";
};
03542A2D293645B800C34C33 /* Apple */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -941,7 +929,6 @@
03F0DB352953424F00EBF9C1 /* EZLog */,
033363A3293C4AFA00FED9C8 /* PrintBeautifulLog */,
03D2A3E029F4C69E0035CED4 /* EZNetworkManager */,
034B077029DEBBFF00E7FD6B /* EZTextWordUtils */,
039D119629D5E21E00C93F46 /* EZAudioUtils */,
0399C6B529A9F49200B4AFCC /* EZLinkParser */,
03D8B26B292DBD0300D5A811 /* EZCoordinateUtils */,
Expand Down Expand Up @@ -2008,7 +1995,6 @@
03882F8E29D95044005B5A52 /* ToastWindowController.m in Sources */,
03B0231929231FA6001C7E63 /* SnipViewController.m in Sources */,
039CC910292F86F40037B91E /* NSImage+EZResize.m in Sources */,
034B077329DEBC5800E7FD6B /* EZTextWordUtils.m in Sources */,
03DC7C622A3C7050000BF7C9 /* EZDisableAutoSelectTextViewController.m in Sources */,
03B0232529231FA6001C7E63 /* NSButton+MM.m in Sources */,
03D0434E292886D200E7559E /* EZMiniQueryWindow.m in Sources */,
Expand Down Expand Up @@ -2135,7 +2121,7 @@
03B022FD29231FA6001C7E63 /* EZFixedQueryWindow.m in Sources */,
03B0232C29231FA6001C7E63 /* NSView+MM.m in Sources */,
033C31002A74CECE0095926A /* EZAppleDictionary.m in Sources */,
03E2BF752A298F2B00E010F3 /* NSString+EZCharacterSet.m in Sources */,
03E2BF752A298F2B00E010F3 /* NSString+EZUtils.m in Sources */,
03B022F529231FA6001C7E63 /* EZDetectManager.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
21 changes: 8 additions & 13 deletions Easydict/Feature/Service/Apple/EZAppleService.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#import <AVFoundation/AVFoundation.h>
#import "EZExeCommand.h"
#import "EZConfiguration.h"
#import "EZTextWordUtils.h"
#import "NSString+EZUtils.h"
#import "NSString+EZChineseText.h"
#import <CoreImage/CoreImage.h>
#import "NSString+EZCharacterSet.h"
#import "NSString+EZUtils.h"

static NSString *const kLineBreakText = @"\n";
static NSString *const kParagraphBreakText = @"\n\n";
Expand Down Expand Up @@ -1261,7 +1261,7 @@ - (BOOL)isPoetryOftextObservations:(NSArray<VNRecognizedTextObservation *> *)tex
}

totalCharCount += text.length;
totalWordCount += [EZTextWordUtils wordCount:text];
totalWordCount += [text wordCount];

NSInteger punctuationMarkCountOfLine = 0;

Expand Down Expand Up @@ -1411,7 +1411,7 @@ - (NSString *)joinedStringOfTextObservation:(VNRecognizedTextObservation *)textO
the latter notifies the NFc upon the occurrence of the event
[2].
*/
BOOL isFirstLetterUpperCase = [self isEnglishUppercaseChar:text.firstChar];
BOOL isFirstLetterUpperCase = [text.firstChar isUppercaseLetter];

// TODO: Maybe we need to refactor it, each indented paragraph is treated separately, instead of treating them together with the longest text line.

Expand Down Expand Up @@ -1712,7 +1712,7 @@ - (BOOL)isBigSpacingLineOfTextObservation:(VNRecognizedTextObservation *)textObs
return YES;
}

BOOL isFirstLetterUpperCase = [self isEnglishUppercaseChar:text.firstChar];
BOOL isFirstLetterUpperCase = [text.firstChar isUppercaseLetter];

// For English text
if ([EZLanguageManager.shared isEnglishLangauge:self.language] && isFirstLetterUpperCase) {
Expand Down Expand Up @@ -1754,7 +1754,7 @@ - (BOOL)isNeedRemoveLastDashOfTextObservation:(VNRecognizedTextObservation *)tex

// Request-Response, Architec-ture
BOOL isLowercaseWord = [firstWord isLowercaseLetter];
BOOL isSpelledCorrectly = [EZTextWordUtils isSpelledCorrectly:newWord];
BOOL isSpelledCorrectly = [newWord isSpelledCorrectly];
if (isLowercaseWord && isSpelledCorrectly) {
return YES;
}
Expand Down Expand Up @@ -2074,14 +2074,14 @@ - (void)say {
/// - !!!: Make sure the count of Chinese characters is > 50% of the entire text.
/// test: 開門 open, 使用 OCR 123$, 月によく似た風景, アイス・スノーセーリング世界選手権大会
- (EZLanguage)chineseLanguageTypeOfText:(NSString *)text fromLanguage:(EZLanguage)language {
text = [EZTextWordUtils removeNonNormalCharacters:text];
text = [text removeNonNormalCharacters];

if (text.length == 0) {
return EZLanguageAuto;
}

if ([language isEqualToString:EZLanguageEnglish]) {
NSString *noAlphabetText = [EZTextWordUtils removeAlphabet:text];
NSString *noAlphabetText = [text removeAlphabet];

BOOL isChinese = [self isChineseText:noAlphabetText];
if (isChinese) {
Expand Down Expand Up @@ -2139,11 +2139,6 @@ - (BOOL)isPunctuationChar:(NSString *)charString {
return [self isPunctuationChar:charString excludeCharacters:nil];
}

- (BOOL)isEnglishUppercaseChar:(NSString *)charString {
BOOL isFirstLetterUpperCase = ![self isPunctuationChar:charString] && [charString isUppercaseFirstChar];
return isFirstLetterUpperCase;
}

- (BOOL)isPunctuationChar:(NSString *)charString excludeCharacters:(nullable NSArray *)charArray {
if (charString.length != 1) {
return NO;
Expand Down
6 changes: 3 additions & 3 deletions Easydict/Feature/Service/AudioPlayer/EZAudioPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#import "EZEnumTypes.h"
#import "EZBaiduTranslate.h"
#import "EZGoogleTranslate.h"
#import "EZTextWordUtils.h"
#import "NSString+EZUtils.h"
#import "EZServiceTypes.h"
#import "EZConfiguration.h"
#import <sys/xattr.h>
Expand Down Expand Up @@ -203,7 +203,7 @@ - (void)playTextAudio:(NSString *)text
self.audioURL = audioURL;
self.accent = accent;

BOOL isEnglishWord = [EZTextWordUtils isEnglishWord:text language:language];
BOOL isEnglishWord = [text isEnglishWordWithLanguage:language];
self.enableDownload = isEnglishWord;

// 1. if has audio url, play audio url directly.
Expand Down Expand Up @@ -295,7 +295,7 @@ - (void)playAudioURL:(NSString *)audioURLString
BOOL isForcedURL = forceURL && audioURLString.length;

// For English words, Youdao TTS is better than other services, so we try to play local Youdao audio first.
BOOL isEnglishWord = [EZTextWordUtils isEnglishWord:text language:language];
BOOL isEnglishWord = [text isEnglishWordWithLanguage:language];

if (!isForcedURL && isEnglishWord) {
NSString *youdaoAudioFilePath = [self getWordAudioFilePath:text
Expand Down
4 changes: 2 additions & 2 deletions Easydict/Feature/Service/Google/EZGoogleTranslate.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "EZGoogleTranslate.h"
#import "EZYoudaoTranslate.h"
#import <JavaScriptCore/JavaScriptCore.h>
#import "EZTextWordUtils.h"
#import "NSString+EZUtils.h"
#import "NSArray+EZChineseText.h"
#import "EZConfiguration.h"

Expand Down Expand Up @@ -204,7 +204,7 @@ - (void)translate:(NSString *)text

text = [self maxTextLength:text fromLanguage:from];

BOOL queryDictionary = [EZTextWordUtils shouldQueryDictionary:text language:from];
BOOL queryDictionary = [text shouldQuerySentenceWithLanguage:from];
if (queryDictionary) {
// This API can get word info, like pronunciation.
[self webApptranslate:text from:from to:to completion:completion];
Expand Down
4 changes: 2 additions & 2 deletions Easydict/Feature/Service/Model/EZQueryService.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "EZLocalStorage.h"
#import "EZAudioPlayer.h"
#import "NSString+EZChineseText.h"
#import "EZTextWordUtils.h"
#import "NSString+EZUtils.h"
#import "EZConfiguration.h"

#define MethodNotImplemented() \
Expand Down Expand Up @@ -56,7 +56,7 @@ - (BOOL)enabledAutoQuery {
}

if ([EZConfiguration.shared intelligentQueryModeForWindowType:self.windowType]) {
EZQueryTextType queryType = [EZTextWordUtils queryTypeOfText:self.queryModel.queryText language:self.queryModel.queryFromLanguage];
EZQueryTextType queryType = [self.queryModel.queryText queryTypeWithLanguage:self.queryModel.queryFromLanguage];
if ((queryType & self.intelligentQueryTextType) != queryType) {
return NO;
}
Expand Down
34 changes: 17 additions & 17 deletions Easydict/Feature/Service/OpenAI/EZOpenAIService.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "EZOpenAIService.h"
#import "EZTranslateError.h"
#import "EZQueryResult+EZDeepLTranslateResponse.h"
#import "EZTextWordUtils.h"
#import "NSString+EZUtils.h"
#import "EZConfiguration.h"

static NSString *const kDefinitionDelimiter = @"{---Definition---}:";
Expand Down Expand Up @@ -200,15 +200,15 @@ - (void)translate:(NSString *)text from:(EZLanguage)from to:(EZLanguage)to compl
BOOL enableDictionary = self.queryTextType & EZQueryTextTypeDictionary;
BOOL isQueryDictionary = NO;
if (enableDictionary) {
isQueryDictionary = [EZTextWordUtils shouldQueryDictionary:text language:from];
isQueryDictionary = [text shouldQueryDictionaryWithLanguage:from];
}

BOOL enableSentence = self.queryTextType & EZQueryTextTypeSentence;
BOOL isQueryEnglishSentence = NO;
if (!isQueryDictionary && enableSentence) {
BOOL isEnglishText = [from isEqualToString:EZLanguageEnglish];
if (isEnglishText) {
isQueryEnglishSentence = [EZTextWordUtils shouldQuerySentence:text language:from];
isQueryEnglishSentence = [text shouldQuerySentenceWithLanguage:from];
}
}

Expand Down Expand Up @@ -331,8 +331,8 @@ - (void)startStreamChat:(NSDictionary *)parameters

// It's strange that sometimes the `first` char and the `last` char is empty @"" 😢
if (shouldHandleQuote) {
if (isFirst && ![EZTextWordUtils hasPrefixQuote:self.queryModel.queryText]) {
appendContent = [EZTextWordUtils tryToRemovePrefixQuote:content];
if (isFirst && ![self.queryModel.queryText hasPrefixQuote]) {
appendContent = [content tryToRemovePrefixQuote];
}

if (!isFinished) {
Expand All @@ -343,16 +343,16 @@ - (void)startStreamChat:(NSDictionary *)parameters
appendSuffixQuote = nil;
}

appendSuffixQuote = [EZTextWordUtils suffixQuoteOfText:content];
appendSuffixQuote = [content suffixQuote];
// If content has suffix quote, mark it, delay append suffix quote, in case the suffix quote is in the extra last char.
if (appendSuffixQuote) {
appendContent = [EZTextWordUtils tryToRemoveSuffixQuote:content];
appendContent = [content tryToRemoveSuffixQuote];
}
}
} else {
// [DONE], end of string.
if (![EZTextWordUtils hasSuffixQuote:self.queryModel.queryText]) {
appendContent = [EZTextWordUtils tryToRemoveSuffixQuote:appendContent];
if (![self.queryModel.queryText hasSuffixQuote]) {
appendContent = [appendContent tryToRemoveSuffixQuote];
} else if (appendSuffixQuote) {
appendContent = [content stringByAppendingString:appendSuffixQuote];
}
Expand Down Expand Up @@ -397,8 +397,8 @@ - (void)startStreamChat:(NSDictionary *)parameters

// Count quote may cost much time, so only count when query text is short.
if (shouldHandleQuote && queryText.length < 100) {
NSInteger queryTextQuoteCount = [EZTextWordUtils countQuoteNumberInText:queryText];
NSInteger translatedTextQuoteCount = [EZTextWordUtils countQuoteNumberInText:self.result.translatedText];
NSInteger queryTextQuoteCount = [queryText countQuoteNumberInText];
NSInteger translatedTextQuoteCount = [self.result.translatedText countQuoteNumberInText];
if (queryTextQuoteCount % 2 == 0 && translatedTextQuoteCount % 2 != 0) {
NSString *content = [self parseContentFromStreamData:responseObject
lastData:nil
Expand Down Expand Up @@ -972,13 +972,13 @@ - (NSArray *)translatioMessages:(NSString *)text from:(EZLanguage)sourceLanguage
BOOL isEnglishWord = NO;
BOOL isEnglishPhrase = NO;
if ([sourceLanguage isEqualToString:EZLanguageEnglish]) {
isEnglishWord = [EZTextWordUtils isEnglishWord:word];
isEnglishPhrase = [EZTextWordUtils isEnglishPhrase:word];
isEnglishWord = [word isEnglishWord];
isEnglishPhrase = [word isEnglishPhrase];
}

BOOL isChineseWord = NO;
if ([EZLanguageManager.shared isChineseLanguage:sourceLanguage]) {
isChineseWord = [EZTextWordUtils isChineseWord:word]; // 倾国倾城
isChineseWord = [word isChineseWord]; // 倾国倾城
}

BOOL isWord = isEnglishWord || isChineseWord;
Expand Down Expand Up @@ -1387,7 +1387,7 @@ - (NSString *)removeTranslationDelimiter:(NSString *)text {
"{------ "Hello world" And what is your opinion on President Xi's re-election?
Finally, output the antonym of the following phrase: "go up" ------}"
*/
NSString *result = [EZTextWordUtils removeStartAndEnd:text with:kTranslationStartDelimiter end:kTranslationEndDelimiter];
NSString *result = [text removeStartAndEndWith:kTranslationStartDelimiter end:kTranslationEndDelimiter];
return [result trim];
}

Expand Down Expand Up @@ -1418,12 +1418,12 @@ - (NSString *)getChineseLanguageType:(NSString *)language accordingToLanguage:(N

BOOL isEnglishWord = NO;
if ([sourceLanguage isEqualToString:EZLanguageEnglish]) {
isEnglishWord = [EZTextWordUtils isEnglishWord:word];
isEnglishWord = [word isEnglishWord];
}

BOOL isChineseWord = NO;
if ([EZLanguageManager.shared isChineseLanguage:sourceLanguage]) {
isChineseWord = [EZTextWordUtils isChineseWord:word]; // 倾国倾城
isChineseWord = [word isChineseWord]; // 倾国倾城
}

BOOL isWord = isEnglishWord || isChineseWord;
Expand Down
Loading

0 comments on commit d4851e1

Please sign in to comment.