commit e934c2bb1140ee8b60288ce85a36cfccd980d5a5
parent fd8ad494e9ab6eefb5c455a5dd5fc459c4c4c039
Author: Terry Yiu <963907+tyiu@users.noreply.github.com>
Date: Sat, 22 Apr 2023 11:39:13 +0200
Fix crash with LibreTranslate server setting selection and remove delisted vern server
Broken after the settings refactor
Changelog-Fixed: Fix crash with LibreTranslate server setting selection and remove delisted vern server
Closes: #998
Diffstat:
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/damus/Models/LibreTranslateServer.swift b/damus/Models/LibreTranslateServer.swift
@@ -7,7 +7,7 @@
import Foundation
-enum LibreTranslateServer: String, CaseIterable, Identifiable {
+enum LibreTranslateServer: String, CaseIterable, Identifiable, StringCodable {
var id: String { self.rawValue }
struct Model: Identifiable, Hashable {
@@ -17,9 +17,19 @@ enum LibreTranslateServer: String, CaseIterable, Identifiable {
var url: String?
}
+ func to_string() -> String {
+ return rawValue
+ }
+
+ init?(from string: String) {
+ guard let libreTranslateServer = LibreTranslateServer(rawValue: string) else {
+ return nil
+ }
+ self = libreTranslateServer
+ }
+
case argosopentech
case terraprint
- case vern
case custom
var model: Model {
@@ -28,8 +38,6 @@ enum LibreTranslateServer: String, CaseIterable, Identifiable {
return .init(tag: self.rawValue, displayName: "translate.argosopentech.com", url: "https://translate.argosopentech.com")
case .terraprint:
return .init(tag: self.rawValue, displayName: "translate.terraprint.co", url: "https://translate.terraprint.co")
- case .vern:
- return .init(tag: self.rawValue, displayName: "lt.vern.cc", url: "https://lt.vern.cc")
case .custom:
return .init(tag: self.rawValue, displayName: NSLocalizedString("Custom", comment: "Dropdown option for selecting a custom translation server."), url: nil)
}
diff --git a/damus/Models/UserSettingsStore.swift b/damus/Models/UserSettingsStore.swift
@@ -162,7 +162,7 @@ class UserSettingsStore: ObservableObject {
}
}
- @Setting(key: "libretranslate_server", default_value: .vern)
+ @StringSetting(key: "libretranslate_server", default_value: .terraprint)
var libretranslate_server: LibreTranslateServer
@Setting(key: "libretranslate_url", default_value: "")