diff --git a/Easydict/App/Localizable.xcstrings b/Easydict/App/Localizable.xcstrings index 9062a9a38..f52a00975 100644 --- a/Easydict/App/Localizable.xcstrings +++ b/Easydict/App/Localizable.xcstrings @@ -2420,6 +2420,70 @@ } } }, + "service.configuration.deepl.translation.title" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "API Usage Priority" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "API 使用优先级" + } + } + } + }, + "service.configuration.deepl.web_first.title" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Web API first" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "优先使用 Web API" + } + } + } + }, + "service.configuration.deepl.authkey_first.title" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Auth Key First" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "优先使用 Auth Key" + } + } + } + }, + "service.configuration.deepl.authkey_only.title" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Auth Key Only" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "仅使用 Auth Key" + } + } + } + }, "service.configuration.deepl.endpoint.placeholder" : { "localizations" : { "en" : { @@ -2516,6 +2580,22 @@ } } }, + "service.configuration.openai.dictionary.title" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Dictionary" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "查单词" + } + } + } + }, "service.configuration.openai.domain.placeholder" : { "localizations" : { "en" : { @@ -2596,22 +2676,6 @@ } } }, - "service.configuration.openai.translation.title" : { - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "Translation" - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "翻译" - } - } - } - }, "service.configuration.openai.sentence.title" : { "localizations" : { "en" : { @@ -2628,18 +2692,18 @@ } } }, - "service.configuration.openai.dictionary.title" : { + "service.configuration.openai.translation.title" : { "localizations" : { "en" : { "stringUnit" : { "state" : "translated", - "value" : "Dictionary" + "value" : "Translation" } }, "zh-Hans" : { "stringUnit" : { "state" : "translated", - "value" : "查单词" + "value" : "翻译" } } } diff --git a/Easydict/NewApp/Configuration/Configuration+Defaults.swift b/Easydict/NewApp/Configuration/Configuration+Defaults.swift index 51fff1dda..b7e03a940 100644 --- a/Easydict/NewApp/Configuration/Configuration+Defaults.swift +++ b/Easydict/NewApp/Configuration/Configuration+Defaults.swift @@ -142,6 +142,7 @@ extension Defaults.Keys { // DEEPL static let deepLAuth = Key("EZDeepLAuthKey") + static let deepLTranslation = Key("EZDeepLTranslationAPIKey", default: DeepLAPIUsagePriority.webFirst.rawValue) static let deepLTranslateEndPointKey = Key("EZDeepLTranslateEndPointKey") // BING diff --git a/Easydict/NewApp/Utility/Extensions/QueryService+ConfigurableService/DeepLTranslate+ConfigurableService.swift b/Easydict/NewApp/Utility/Extensions/QueryService+ConfigurableService/DeepLTranslate+ConfigurableService.swift index 474cfc774..63ab97433 100644 --- a/Easydict/NewApp/Utility/Extensions/QueryService+ConfigurableService/DeepLTranslate+ConfigurableService.swift +++ b/Easydict/NewApp/Utility/Extensions/QueryService+ConfigurableService/DeepLTranslate+ConfigurableService.swift @@ -9,6 +9,25 @@ import Foundation import SwiftUI +enum DeepLAPIUsagePriority: String, CaseIterable, Hashable { + case webFirst = "0" + case authKeyFirst = "1" + case authKeyOnly = "2" +} + +extension DeepLAPIUsagePriority: EnumLocalizedStringConvertible { + var title: String { + switch self { + case .webFirst: + return NSLocalizedString("service.configuration.deepl.web_first.title", bundle: .main, comment: "") + case .authKeyFirst: + return NSLocalizedString("service.configuration.deepl.authkey_first.title", bundle: .main, comment: "") + case .authKeyOnly: + return NSLocalizedString("service.configuration.deepl.authkey_only.title", bundle: .main, comment: "") + } + } +} + @available(macOS 13.0, *) extension EZDeepLTranslate: ConfigurableService { func configurationListItems() -> some View { @@ -23,6 +42,12 @@ extension EZDeepLTranslate: ConfigurableService { key: .deepLTranslateEndPointKey, placeholder: "service.configuration.deepl.endpoint.placeholder" ) + + ServiceConfigurationPickerCell( + titleKey: "service.configuration.deepl.translation.title", + key: .deepLTranslation, + values: DeepLAPIUsagePriority.allCases + ) } } } diff --git a/Easydict/NewApp/Utility/Extensions/QueryService+ConfigurableService/OpenAIService+ConfigurableService.swift b/Easydict/NewApp/Utility/Extensions/QueryService+ConfigurableService/OpenAIService+ConfigurableService.swift index 85fc32db1..95960a4cc 100644 --- a/Easydict/NewApp/Utility/Extensions/QueryService+ConfigurableService/OpenAIService+ConfigurableService.swift +++ b/Easydict/NewApp/Utility/Extensions/QueryService+ConfigurableService/OpenAIService+ConfigurableService.swift @@ -9,6 +9,10 @@ import Foundation import SwiftUI +protocol EnumLocalizedStringConvertible { + var title: String { get } +} + enum OpenAIModels: String, CaseIterable, Identifiable { var id: Self { self @@ -20,6 +24,12 @@ enum OpenAIModels: String, CaseIterable, Identifiable { case gpt4_32k = "gpt-4-32k" } +extension OpenAIModels: EnumLocalizedStringConvertible { + var title: String { + rawValue + } +} + @available(macOS 13.0, *) extension EZOpenAIService: ConfigurableService { func configurationListItems() -> some View { diff --git a/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationCells.swift b/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationCells.swift index 2f1eccbdb..90267bd25 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationCells.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationCells.swift @@ -49,7 +49,9 @@ struct ServiceConfigurationInputCell: View { } @available(macOS 13.0, *) -struct ServiceConfigurationPickerCell: View where T.RawValue: StringProtocol { +struct ServiceConfigurationPickerCell: View + where T.RawValue: StringProtocol +{ @Default var value: String let titleKey: LocalizedStringKey let values: [T] @@ -63,7 +65,8 @@ struct ServiceConfigurationPickerCell: View wher var body: some View { Picker(titleKey, selection: $value) { ForEach(values, id: \.rawValue) { value in - Text(value.rawValue) + Text(value.title) + .tag(value.rawValue) } } .padding(10.0)