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 import SwiftUI
struct StatusRowContextMenu: View { struct StatusRowContextMenu: View {
@EnvironmentObject private var preferences: UserPreferences
@EnvironmentObject private var account: CurrentAccount @EnvironmentObject private var account: CurrentAccount
@EnvironmentObject private var routerPath: RouterPath @EnvironmentObject private var routerPath: RouterPath
@ -75,6 +76,17 @@ struct StatusRowContextMenu: View {
Label("status.action.copy-text", systemImage: "doc.on.doc") 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 { if account.account?.id == viewModel.status.account.id {
Section("status.action.section.your-post") { Section("status.action.section.your-post") {
Button { Button {

View file

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