Skip to content

Commit

Permalink
add word collocation and change ui position
Browse files Browse the repository at this point in the history
  • Loading branch information
choykarl committed Nov 29, 2023
1 parent 356c65b commit 694c907
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
17 changes: 17 additions & 0 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,23 @@
}
}
},
"collocation" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Collocation"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "搭配"
}
}
}
},
"comparative" : {
"localizations" : {
"en" : {
Expand Down
15 changes: 15 additions & 0 deletions Easydict/Feature/Service/Bing/EZBingService.m
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ - (void)parseBingDictTranslate:(NSDictionary *)json word:(NSString *)word comple
NSMutableArray<EZWordPhonetic *> *phonetics = [NSMutableArray array];
NSMutableArray<EZTranslatePart *> *synonyms = [NSMutableArray array];
NSMutableArray<EZTranslatePart *> *antonyms = [NSMutableArray array];
NSMutableArray<EZTranslatePart *> *collocation = [NSMutableArray array];

for (NSDictionary *meaningGroup in meaningGroups) {
NSArray *partOfSpeech = meaningGroup[@"partsOfSpeech"];
Expand Down Expand Up @@ -429,6 +430,17 @@ - (void)parseBingDictTranslate:(NSDictionary *)json word:(NSString *)word comple
antonymsPart.means = antonymMeans;
[antonyms addObject:antonymsPart];
}
} else if ([description isEqualToString:@"搭配"]) {
NSArray *means = [fragments mm_map:^id _Nullable(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
return obj[@"text"];
}];
if (means.count > 5) {
means = [means subarrayWithRange:NSMakeRange(0, 5)];
}
EZTranslatePart *collocationPart = [EZTranslatePart new];
collocationPart.part = name;
collocationPart.means = means;
[collocation addObject:collocationPart];
}

if ([name isEqualToString:@"变形"]) {
Expand Down Expand Up @@ -468,6 +480,9 @@ - (void)parseBingDictTranslate:(NSDictionary *)json word:(NSString *)word comple
if (antonyms.count) {
wordResult.antonyms = antonyms;
}
if (collocation.count) {
wordResult.collocation = collocation;
}
self.result.from = EZLanguageEnglish;
self.result.to = EZLanguageSimplifiedChinese;

Expand Down
2 changes: 2 additions & 0 deletions Easydict/Feature/Service/Model/EZQueryResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy, nullable) NSArray<EZTranslatePart *> *synonyms;
/// 反义词
@property (nonatomic, copy, nullable) NSArray<EZTranslatePart *> *antonyms;
/// 搭配
@property (nonatomic, copy, nullable) NSArray<EZTranslatePart *> *collocation;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,17 +531,6 @@ - (void)refreshWithResult:(EZQueryResult *)result {
lastView = meanLabel;
}];

//同义词
if (result.wordResult.synonyms.count) {
lastView = [self buildSynonymsAndAntonymsView:NSLocalizedString(@"synonyms", nil) parts:result.wordResult.synonyms textColor:typeTextColor typeTextFont:typeTextFont height:&height lastView:lastView];
}

//反义词
if (result.wordResult.antonyms.count) {
lastView = [self buildSynonymsAndAntonymsView:NSLocalizedString(@"antonyms", nil) parts:result.wordResult.antonyms textColor:typeTextColor typeTextFont:typeTextFont height:&height lastView:lastView];
}


[wordResult.exchanges enumerateObjectsUsingBlock:^(EZTranslateExchange *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {
EZLabel *exchangeLabel = [[EZLabel alloc] init];
[self addSubview:exchangeLabel];
Expand Down Expand Up @@ -597,6 +586,21 @@ - (void)refreshWithResult:(EZQueryResult *)result {
}];
}];

// 同义词
if (result.wordResult.synonyms.count) {
lastView = [self buildSynonymsAndAntonymsView:NSLocalizedString(@"synonyms", nil) parts:result.wordResult.synonyms textColor:typeTextColor typeTextFont:typeTextFont height:&height lastView:lastView];
}

// 反义词
if (result.wordResult.antonyms.count) {
lastView = [self buildSynonymsAndAntonymsView:NSLocalizedString(@"antonyms", nil) parts:result.wordResult.antonyms textColor:typeTextColor typeTextFont:typeTextFont height:&height lastView:lastView];
}

// 搭配
if (result.wordResult.collocation.count) {
lastView = [self buildSynonymsAndAntonymsView:NSLocalizedString(@"collocation", nil) parts:result.wordResult.collocation textColor:typeTextColor typeTextFont:typeTextFont height:&height lastView:lastView];
}

__block NSString *lastSimpleWordPart = nil;
[wordResult.simpleWords enumerateObjectsUsingBlock:^(EZTranslateSimpleWord *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {
EZLabel *partLabel = nil;
Expand Down

0 comments on commit 694c907

Please sign in to comment.