mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-06-02 21:39:36 +00:00
Make Apple and the instance a fallback
Apple Translate is now a fallback for both other translation types, the instance service is a fallback for DeepL.
This commit is contained in:
parent
7de6a0f007
commit
218553d1cf
|
@ -315,29 +315,35 @@ import SwiftUI
|
|||
return
|
||||
}
|
||||
|
||||
withAnimation {
|
||||
isLoadingTranslation = true
|
||||
}
|
||||
if preferredTranslationType != .useDeepl {
|
||||
let translation: Translation? = try? await client.post(endpoint: Statuses.translate(id: finalStatus.id,
|
||||
lang: userLang))
|
||||
|
||||
await translateWithInstance(userLang: userLang)
|
||||
|
||||
if translation == nil {
|
||||
await translateWithDeepL(userLang: userLang)
|
||||
} else {
|
||||
withAnimation {
|
||||
self.translation = translation
|
||||
isLoadingTranslation = false
|
||||
}
|
||||
}
|
||||
|
||||
if self.translation == nil {
|
||||
instanceTranslationError = true
|
||||
}
|
||||
} else {
|
||||
await translateWithDeepL(userLang: userLang)
|
||||
|
||||
if translation == nil {
|
||||
await translateWithInstance(userLang: userLang)
|
||||
}
|
||||
}
|
||||
|
||||
var hasShown = false
|
||||
#if canImport(_Translation_SwiftUI)
|
||||
if translation == nil,
|
||||
#available(iOS 17.4, *) {
|
||||
showAppleTranslation = true
|
||||
hasShown = true
|
||||
}
|
||||
#endif
|
||||
|
||||
if !hasShown,
|
||||
translation == nil {
|
||||
if preferredTranslationType == .useDeepl {
|
||||
deeplTranslationError = true
|
||||
} else {
|
||||
instanceTranslationError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -355,6 +361,20 @@ import SwiftUI
|
|||
isLoadingTranslation = false
|
||||
}
|
||||
}
|
||||
|
||||
func translateWithInstance(userLang: String) async {
|
||||
withAnimation {
|
||||
isLoadingTranslation = true
|
||||
}
|
||||
|
||||
let translation: Translation? = try? await client.post(endpoint: Statuses.translate(id: finalStatus.id,
|
||||
lang: userLang))
|
||||
|
||||
withAnimation {
|
||||
self.translation = translation
|
||||
isLoadingTranslation = false
|
||||
}
|
||||
}
|
||||
|
||||
private func getDeepLClient() -> DeepLClient {
|
||||
let userAPIfree = UserPreferences.shared.userDeeplAPIFree
|
||||
|
|
Loading…
Reference in a new issue