Skip to content

Commit

Permalink
Add basic support for CaiyunService
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Nov 6, 2023
1 parent aa1fc17 commit 8a1d6d6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,17 @@
}
}
},
"caiyun_translate" : {
"comment" : "The name of Caiyun Translate",
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "彩云小译"
}
}
}
},
"cancel" : {
"localizations" : {
"en" : {
Expand Down
30 changes: 30 additions & 0 deletions Easydict/Feature/Service/Caiyun/CaiyunService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,34 @@ import Foundation
@objc(EZCaiyunService)
public final class CaiyunService: QueryService {

public override func serviceType() -> ServiceType {
.caiyun
}

public override func link() -> String? {
"https://fanyi.caiyunapp.com"
}

public override func name() -> String {
NSLocalizedString("caiyun_translate", comment: "The name of Caiyun Translate")
}

public override func supportLanguagesDictionary() -> MMOrderedDictionary<AnyObject, AnyObject> {
// TODO: Replace MMOrderedDictionary in the API
let orderedDict = MMOrderedDictionary<AnyObject, AnyObject>()
orderedDict.setObject(Language.auto.rawValue as NSString, forKey: "auto" as NSString)
orderedDict.setObject(Language.simplifiedChinese.rawValue as NSString, forKey: "zh" as NSString)
orderedDict.setObject(Language.english.rawValue as NSString, forKey: "en" as NSString)
orderedDict.setObject(Language.japanese.rawValue as NSString, forKey: "ja" as NSString)
return orderedDict
}

public override func ocr(_ queryModel: EZQueryModel) async throws -> EZOCRResult {
NSLog("Caiyun Translate does not support OCR")
throw QueryServiceError.notSupported
}
}

enum QueryServiceError: Error {
case notSupported
}
2 changes: 1 addition & 1 deletion Easydict/Feature/Service/Language/EZLanguageModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
NS_ASSUME_NONNULL_BEGIN

// Refer Apple NLLanguage.
typedef NSString *EZLanguage NS_STRING_ENUM;
typedef NSString *EZLanguage NS_STRING_ENUM NS_SWIFT_NAME(Language);

// 目前总计支持 49 种语言:简体中文,繁体中文,文言文,英语,日语,韩语,法语,西班牙语,葡萄牙语,意大利语,德语,俄语,阿拉伯语,瑞典语,罗马尼亚语,泰语,斯洛伐克语,荷兰语,匈牙利语,希腊语,丹麦语,芬兰语,波兰语,捷克语,土耳其语,立陶宛语,拉脱维亚语,乌克兰语,保加利亚语,印尼语,马来语,斯洛文尼亚语,爱沙尼亚语,越南语,波斯语,印地语,泰卢固语,泰米尔语,乌尔都语,菲律宾语,高棉语,老挝语,孟加拉语,缅甸语,挪威语,塞尔维亚语,克罗地亚语,蒙古语,希伯来语。

Expand Down
2 changes: 1 addition & 1 deletion Easydict/Feature/Service/Model/EZEnumTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef NS_ENUM(NSUInteger, EZShowWindowPosition) {

FOUNDATION_EXPORT NSString *const EZServiceTypeKey;

typedef NSString *EZServiceType NS_STRING_ENUM;
typedef NSString *EZServiceType NS_STRING_ENUM NS_SWIFT_NAME(ServiceType);
FOUNDATION_EXPORT EZServiceType const EZServiceTypeGoogle;
FOUNDATION_EXPORT EZServiceType const EZServiceTypeBaidu;
FOUNDATION_EXPORT EZServiceType const EZServiceTypeYoudao;
Expand Down

0 comments on commit 8a1d6d6

Please sign in to comment.