release v1.2 (#5)
- Support for api's that use keys - Removed idle instances. --------- Co-authored-by: Viktor Kalyniuk <@> Co-authored-by: Simon Rieger <simono41@brothertec.eu>
This commit is contained in:
parent
5ac00486dc
commit
3474967700
7 changed files with 37 additions and 11 deletions
|
@ -8,14 +8,15 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct TranslationParsing {
|
struct TranslationParsing {
|
||||||
static func parse(url: String, text: String, inputLanguage: Languages, outputLanguage: Languages, handler: @escaping(TranslationDecode) -> Void) {
|
static func parse(url: String, text: String, inputLanguage: Languages, outputLanguage: Languages, key: String, handler: @escaping(TranslationDecode) -> Void) {
|
||||||
if let url = URL(string: url) {
|
if let url = URL(string: url) {
|
||||||
let session = URLSession.shared
|
let session = URLSession.shared
|
||||||
let parameters: [String: String] = [
|
let parameters: [String: String] = [
|
||||||
"q": "\(text)",
|
"q": "\(text)",
|
||||||
"source": "\(inputLanguage.rawValue)",
|
"source": "\(inputLanguage.rawValue)",
|
||||||
"target": "\(outputLanguage.rawValue)",
|
"target": "\(outputLanguage.rawValue)",
|
||||||
"format": "text"
|
"format": "text",
|
||||||
|
"api_key": "\(key)"
|
||||||
]
|
]
|
||||||
|
|
||||||
var request = URLRequest(url: url)
|
var request = URLRequest(url: url)
|
||||||
|
|
|
@ -11,6 +11,7 @@ import SwiftUI
|
||||||
class InstanceURL: ObservableObject {
|
class InstanceURL: ObservableObject {
|
||||||
@AppStorage(Keys.libreTranslateDefaultURL) var defaultURL: Links.LibreTranslateMirrors = Links.LibreTranslateMirrors.de
|
@AppStorage(Keys.libreTranslateDefaultURL) var defaultURL: Links.LibreTranslateMirrors = Links.LibreTranslateMirrors.de
|
||||||
@AppStorage(Keys.libreTranslateSelfHostURL) var selfHostURL: String = ""
|
@AppStorage(Keys.libreTranslateSelfHostURL) var selfHostURL: String = ""
|
||||||
|
@AppStorage(Keys.libreTranslateSelfHostKey) var selfHostKey: String = ""
|
||||||
|
|
||||||
func getURL() -> String {
|
func getURL() -> String {
|
||||||
if selfHostURL.isEmpty {
|
if selfHostURL.isEmpty {
|
||||||
|
@ -19,4 +20,8 @@ class InstanceURL: ObservableObject {
|
||||||
|
|
||||||
return selfHostURL
|
return selfHostURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getKey() -> String {
|
||||||
|
return selfHostKey
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import Foundation
|
||||||
struct Keys {
|
struct Keys {
|
||||||
static let bookmarks: String = "bookmarks"
|
static let bookmarks: String = "bookmarks"
|
||||||
static let libreTranslateSelfHostURL: String = "libreTranslateSelfHostURL"
|
static let libreTranslateSelfHostURL: String = "libreTranslateSelfHostURL"
|
||||||
|
static let libreTranslateSelfHostKey: String = "libreTranslateSelfHostKey"
|
||||||
static let libreTranslateDefaultURL: String = "libreTranslateURL"
|
static let libreTranslateDefaultURL: String = "libreTranslateURL"
|
||||||
static let languageInputSelection: String = "languageInputSelection"
|
static let languageInputSelection: String = "languageInputSelection"
|
||||||
static let languageOutputSelection: String = "languageOutputSelection"
|
static let languageOutputSelection: String = "languageOutputSelection"
|
||||||
|
|
|
@ -14,9 +14,9 @@ struct Links {
|
||||||
case de = "https://libretranslate.de/translate"
|
case de = "https://libretranslate.de/translate"
|
||||||
case argosopentech = "https://translate.argosopentech.com/translate"
|
case argosopentech = "https://translate.argosopentech.com/translate"
|
||||||
// case skitzen = "https://translate.api.skitzen.com/translate"
|
// case skitzen = "https://translate.api.skitzen.com/translate"
|
||||||
case fortytwo = "https://translate.fortytwo-it.com/translate"
|
// case fortytwo = "https://translate.fortytwo-it.com/translate"
|
||||||
case terraprint = "https://translate.terraprint.co/translate"
|
case terraprint = "https://translate.terraprint.co/translate"
|
||||||
case vern = "https://lt.vern.cc/translate"
|
// case vern = "https://lt.vern.cc/translate"
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Info {
|
struct Info {
|
||||||
|
|
|
@ -42,7 +42,9 @@ struct InputBottomButtons: View {
|
||||||
.parse(url: instance.getURL(),
|
.parse(url: instance.getURL(),
|
||||||
text: textData.input,
|
text: textData.input,
|
||||||
inputLanguage: selection.input,
|
inputLanguage: selection.input,
|
||||||
outputLanguage: selection.output) { data in
|
outputLanguage: selection.output,
|
||||||
|
key: instance.getKey()
|
||||||
|
) { data in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
textData.output = data.translatedText
|
textData.output = data.translatedText
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,9 @@ struct ChooseLanguagesView: View {
|
||||||
.parse(url: instance.getURL(),
|
.parse(url: instance.getURL(),
|
||||||
text: textData.input,
|
text: textData.input,
|
||||||
inputLanguage: selection.input,
|
inputLanguage: selection.input,
|
||||||
outputLanguage: selection.output) { data in
|
outputLanguage: selection.output,
|
||||||
|
key: instance.getKey()
|
||||||
|
) { data in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
textData.output = data.translatedText
|
textData.output = data.translatedText
|
||||||
}
|
}
|
||||||
|
@ -48,7 +50,9 @@ struct ChooseLanguagesView: View {
|
||||||
.parse(url: instance.getURL(),
|
.parse(url: instance.getURL(),
|
||||||
text: textData.input,
|
text: textData.input,
|
||||||
inputLanguage: selection.input,
|
inputLanguage: selection.input,
|
||||||
outputLanguage: selection.output) { data in
|
outputLanguage: selection.output,
|
||||||
|
key: instance.getKey()
|
||||||
|
) { data in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
textData.output = data.translatedText
|
textData.output = data.translatedText
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,13 @@ struct SelfHostingView: View {
|
||||||
|
|
||||||
@Environment(\.presentationMode) var mode: Binding<PresentationMode>
|
@Environment(\.presentationMode) var mode: Binding<PresentationMode>
|
||||||
|
|
||||||
@State private var input: String = ""
|
@State private var inputURL: String = ""
|
||||||
|
@State private var inputKey: String = ""
|
||||||
|
|
||||||
private let selfHostingTitle = "Self Hosting"
|
private let selfHostingTitle = "Self Hosting"
|
||||||
private let textFieldTitle = "url"
|
private let textFieldTitle = "url"
|
||||||
|
private let selfApiTitle = "API Key (if needed)"
|
||||||
|
private let textApiTitle = "key"
|
||||||
private let useInstanceTitle = "Use default instance"
|
private let useInstanceTitle = "Use default instance"
|
||||||
private let infoTitle = "Info"
|
private let infoTitle = "Info"
|
||||||
private let instructionTitle = "Instruction"
|
private let instructionTitle = "Instruction"
|
||||||
|
@ -24,9 +27,18 @@ struct SelfHostingView: View {
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
Section(selfHostingTitle) {
|
Section(selfHostingTitle) {
|
||||||
TextField(textFieldTitle, text: $input)
|
TextField(textFieldTitle, text: $inputURL)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
input = instance.selfHostURL
|
inputURL = instance.selfHostURL
|
||||||
|
}
|
||||||
|
.listRowBackground(Colors.Background.primaryView)
|
||||||
|
.foregroundColor(Colors.Foreground.label)
|
||||||
|
}
|
||||||
|
.textCase(nil)
|
||||||
|
Section(selfApiTitle) {
|
||||||
|
TextField(textApiTitle, text: $inputKey)
|
||||||
|
.onAppear {
|
||||||
|
inputKey = instance.selfHostKey
|
||||||
}
|
}
|
||||||
.listRowBackground(Colors.Background.primaryView)
|
.listRowBackground(Colors.Background.primaryView)
|
||||||
.foregroundColor(Colors.Foreground.label)
|
.foregroundColor(Colors.Foreground.label)
|
||||||
|
@ -59,7 +71,8 @@ struct SelfHostingView: View {
|
||||||
.background(Colors.Background.mainView)
|
.background(Colors.Background.mainView)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
Button {
|
Button {
|
||||||
instance.selfHostURL = input
|
instance.selfHostURL = inputURL
|
||||||
|
instance.selfHostKey = inputKey
|
||||||
self.mode.wrappedValue.dismiss()
|
self.mode.wrappedValue.dismiss()
|
||||||
} label: {
|
} label: {
|
||||||
Text(doneTitle)
|
Text(doneTitle)
|
||||||
|
|
Loading…
Reference in a new issue