This commit integrates the Damus Purple translation service: - Automatically handles translation settings change after purchase - Asks for permission to override translation settings if the user already has translation setup - Translation settings can be changed with Damus Purple, if desired - Translation requests working with the Damus API server Testing -------- PASS Device: iPhone 15 simulator iOS: 17.2 Damus: This commit Damus Purple API server: `9397201d7d55ddcec4c18fcd337f759b61dce697` running on Ubuntu 22.04 LTS VM (npm run dev) iOS setting: English set as the only preferred language. Steps: 1. Enable Damus Purple feature flag on developer settings, set purple localhost mode, and restart app 2. Set translation setting to something other than none (e.g. DeepL) 3. Simulate Damus Purple purchase 4. Check that when dismissing welcome view, a confirmation prompt will ask the user whether they want to switch translator to Damus Purple. PASS 5. Click "Yes". 6. Go to translation settings. Check that translation settings are set to "Purple". PASS 7. Go to a non-English profile. Check that translations appear with "Mock translation" (Which is the translation text provided by the mock translation server). PASS 8. Reinstall app 9. Repeat the test, but this time starting with no translation settings. Make sure that translation settings will automatically switch to Damus Purple. PASS Feature flag testing -------------------- PASS Preconditions: Same as above Steps: 1. Turn off translation 2. Turn off Damus Purple feature flag 3. Go to translation settings. Make sure that Damus Purple is not an option. PASS Closes: https://github.com/damus-io/damus/issues/1836 Signed-off-by: Daniel D’Aquino <daniel@daquino.me> Reviewed-by: William Casarin <jb55@jb55.com> Signed-off-by: William Casarin <jb55@jb55.com>
55 lines
2.1 KiB
Swift
55 lines
2.1 KiB
Swift
//
|
|
// TranslationService.swift
|
|
// damus
|
|
//
|
|
// Created by Terry Yiu on 2/3/23.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
enum TranslationService: String, CaseIterable, Identifiable, StringCodable {
|
|
init?(from string: String) {
|
|
guard let ts = TranslationService(rawValue: string) else {
|
|
return nil
|
|
}
|
|
|
|
self = ts
|
|
}
|
|
|
|
func to_string() -> String {
|
|
return self.rawValue
|
|
}
|
|
|
|
var id: String { self.rawValue }
|
|
|
|
struct Model: Identifiable, Hashable {
|
|
var id: String { self.tag }
|
|
var tag: String
|
|
var displayName: String
|
|
}
|
|
|
|
case none
|
|
case purple
|
|
case libretranslate
|
|
case deepl
|
|
case nokyctranslate
|
|
case winetranslate
|
|
|
|
var model: Model {
|
|
switch self {
|
|
case .none:
|
|
return .init(tag: self.rawValue, displayName: NSLocalizedString("none_translation_service", value: "None", comment: "Dropdown option for selecting no translation service."))
|
|
case .purple:
|
|
return .init(tag: self.rawValue, displayName: NSLocalizedString("Damus Purple", comment: "Dropdown option for selecting Damus Purple as a translation service."))
|
|
case .libretranslate:
|
|
return .init(tag: self.rawValue, displayName: NSLocalizedString("LibreTranslate (Open Source)", comment: "Dropdown option for selecting LibreTranslate as the translation service."))
|
|
case .deepl:
|
|
return .init(tag: self.rawValue, displayName: NSLocalizedString("DeepL (Proprietary, Higher Accuracy)", comment: "Dropdown option for selecting DeepL as the translation service."))
|
|
case .nokyctranslate:
|
|
return .init(tag: self.rawValue, displayName: NSLocalizedString("NoKYCTranslate.com (Prepay with BTC)", comment: "Dropdown option for selecting NoKYCTranslate.com as the translation service."))
|
|
case .winetranslate:
|
|
return .init(tag: self.rawValue, displayName: NSLocalizedString("translate.nostr.wine (DeepL, Pay with BTC)", comment: "Dropdown option for selecting translate.nostr.wine as the translation service."))
|
|
}
|
|
}
|
|
}
|