Skip to content

Commit

Permalink
perf: update handling of language
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry23011 committed Dec 2, 2023
1 parent b3de7cf commit 41dcc76
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
6 changes: 5 additions & 1 deletion Easydict/Feature/Service/Tencent/TencentService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public final class TencentService: QueryService {
NSLog("Tencent Translate currently does not support OCR")
throw QueryServiceError.notSupported
}


override public func autoConvertTraditionalChinese() -> Bool {
return true
}

// MARK: API Request

private static let defaultSecretId = ""
Expand Down
39 changes: 20 additions & 19 deletions Easydict/Feature/Service/Tencent/TencentTranslateType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ struct TencentTranslateType: Equatable {
static let unsupported = TencentTranslateType(sourceLanguage: "unsupported", targetLanguage: "unsupported")

static let supportedTypes: [Language: [Language]] = [
.simplifiedChinese: [.traditionalChinese, .english, .japanese, .korean, .french, .spanish, .italian, .german, .turkish, .russian, .portuguese, .vietnamese, .indonesian, .thai, .malay],
.traditionalChinese: [.simplifiedChinese, .english, .japanese, .korean, .french, .spanish, .italian, .german, .turkish, .russian, .portuguese, .vietnamese, .indonesian, .thai, .malay],
.english: [.simplifiedChinese, .traditionalChinese, .japanese, .korean, .french, .spanish, .italian, .german, .turkish, .russian, .portuguese, .vietnamese, .indonesian, .thai, .malay, .arabic, .hindi],
.japanese: [.simplifiedChinese, .traditionalChinese, .english, .korean],
.korean: [.simplifiedChinese, .traditionalChinese, .english, .japanese],
.french: [.simplifiedChinese, .traditionalChinese, .english, .spanish, .italian, .german, .turkish, .russian, .portuguese],
.spanish: [.simplifiedChinese, .traditionalChinese, .english, .french, .italian, .german, .turkish, .russian, .portuguese],
.italian: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .german, .turkish, .russian, .portuguese],
.german: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .turkish, .russian, .portuguese],
.turkish: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .german, .russian, .portuguese],
.russian: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .german, .turkish, .portuguese],
.portuguese: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .german, .turkish, .russian],
.vietnamese: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .german, .turkish, .russian],
.indonesian: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .german, .turkish, .russian],
.thai: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .german, .turkish, .russian],
.malay: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .german, .turkish, .russian],
.arabic: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .german, .turkish, .russian],
.hindi: [.simplifiedChinese, .traditionalChinese, .english, .french, .spanish, .italian, .german, .turkish, .russian]
.simplifiedChinese: [.english, .japanese, .korean, .french, .spanish, .italian, .german, .turkish, .russian, .portuguese, .vietnamese, .indonesian, .thai, .malay],
.traditionalChinese: [.english, .japanese, .korean, .french, .spanish, .italian, .german, .turkish, .russian, .portuguese, .vietnamese, .indonesian, .thai, .malay],
.english: [.simplifiedChinese, .japanese, .korean, .french, .spanish, .italian, .german, .turkish, .russian, .portuguese, .vietnamese, .indonesian, .thai, .malay, .arabic, .hindi],
.japanese: [.simplifiedChinese, .english, .korean],
.korean: [.simplifiedChinese, .english, .japanese],
.french: [.simplifiedChinese, .english, .spanish, .italian, .german, .turkish, .russian, .portuguese],
.spanish: [.simplifiedChinese, .english, .french, .italian, .german, .turkish, .russian, .portuguese],
.italian: [.simplifiedChinese, .english, .french, .spanish, .german, .turkish, .russian, .portuguese],
.german: [.simplifiedChinese, .english, .french, .spanish, .italian, .turkish, .russian, .portuguese],
.turkish: [.simplifiedChinese, .english, .french, .spanish, .italian, .german, .russian, .portuguese],
.russian: [.simplifiedChinese, .english, .french, .spanish, .italian, .german, .turkish, .portuguese],
.portuguese: [.simplifiedChinese, .english, .french, .spanish, .italian, .german, .turkish, .russian],
.vietnamese: [.simplifiedChinese, .english],
.indonesian: [.simplifiedChinese, .english],
.thai: [.simplifiedChinese, .english],
.malay: [.simplifiedChinese, .english],
.arabic: [.simplifiedChinese, .english],
.hindi: [.simplifiedChinese, .english]
]

static let supportLanguagesDictionary: [Language: String] = [
Expand All @@ -59,7 +59,8 @@ struct TencentTranslateType: Equatable {
]

static func transType(from: Language, to: Language) -> TencentTranslateType {
if supportedTypes[from]?.contains(to) == true {
if (supportedTypes[from] != nil && to == .traditionalChinese) ||
(supportedTypes[from]?.contains(to) == true) {
guard let from = supportLanguagesDictionary[from],
let to = supportLanguagesDictionary[to] else {
return .unsupported
Expand Down

0 comments on commit 41dcc76

Please sign in to comment.