Skip to content

Commit

Permalink
perf: do not need extra check when querying Youdao dict
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng committed Apr 12, 2024
1 parent 7d7c8d4 commit 126faaa
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Easydict/objc/Service/Youdao/EZYoudaoTranslate.m
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,11 @@ - (void)queryYoudaoDict:(NSString *)text from:(EZLanguage)from to:(EZLanguage)to

BOOL enableDictionary = self.queryTextType & EZQueryTextTypeDictionary;

// Youdao dict can query word, phrase, even short text.
BOOL shouldQueryDictionary = [text shouldQueryDictionaryWithLanguage:from maxWordCount:1];

NSString *foreignLangauge = [self youdaoDictForeignLangauge:self.queryModel];
BOOL supportQueryDictionaryLanguage = foreignLangauge != nil;

// If Youdao Dictionary does not support the language, try querying translate API.
if (!enableDictionary || !supportQueryDictionaryLanguage || !shouldQueryDictionary) {
if (!enableDictionary || !supportQueryDictionaryLanguage) {
completion(self.result, [EZError errorWithType:EZErrorTypeNoResultsFound]);
return;
}
Expand All @@ -522,6 +519,7 @@ - (void)queryYoudaoDict:(NSString *)text from:(EZLanguage)from to:(EZLanguage)to

NSURLSessionTask *task = [self.jsonSession GET:url parameters:params progress:nil success:^(NSURLSessionDataTask *_Nonnull task, id _Nullable responseObject) {
NSString *message = nil;

if (responseObject) {
@try {
EZYoudaoDictModel *model = [EZYoudaoDictModel mj_objectWithKeyValues:responseObject];
Expand Down

0 comments on commit 126faaa

Please sign in to comment.