Add a translate entry on the status context menu Fix #258

This commit is contained in:
Thomas Ricouard 2023-01-22 09:31:29 +01:00
parent 921d28a57a
commit 987f259130
2 changed files with 18 additions and 5 deletions

View file

@ -3,6 +3,7 @@ import Foundation
import SwiftUI
struct StatusRowContextMenu: View {
@EnvironmentObject private var preferences: UserPreferences
@EnvironmentObject private var account: CurrentAccount
@EnvironmentObject private var routerPath: RouterPath
@ -74,6 +75,17 @@ struct StatusRowContextMenu: View {
} label: {
Label("status.action.copy-text", systemImage: "doc.on.doc")
}
if let lang = preferences.serverPreferences?.postLanguage ?? Locale.current.language.languageCode?.identifier,
viewModel.status.language != lang {
Button {
Task {
await viewModel.translate(userLang: lang)
}
} label: {
Label("status.action.translate", systemImage: "captions.bubble")
}
}
if account.account?.id == viewModel.status.account.id {
Section("status.action.section.your-post") {

View file

@ -235,10 +235,8 @@ public struct StatusRowView: View {
})
Spacer()
}
if preferences.showTranslateButton {
makeTranslateView(status: status)
}
makeTranslateView(status: status)
if let poll = status.poll {
StatusPollView(poll: poll, status: status)
@ -288,6 +286,7 @@ public struct StatusRowView: View {
@ViewBuilder
private func makeTranslateView(status: AnyStatus) -> some View {
if let userLang = preferences.serverPreferences?.postLanguage,
preferences.showTranslateButton,
status.language != nil,
userLang != status.language,
!status.content.asRawText.isEmpty,
@ -304,7 +303,9 @@ public struct StatusRowView: View {
Text("status.action.translate")
}
}
} else if let translation = viewModel.translation {
}
if let translation = viewModel.translation {
GroupBox {
VStack(alignment: .leading, spacing: 4) {
Text(translation)