diff --git a/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift b/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift index 100aa8058..1df4d714b 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift @@ -90,8 +90,7 @@ extension StatusTableViewCell { } .store(in: &_disposeBag) - statusView.viewModel - .$translation + statusView.viewModel.$translation .receive(on: DispatchQueue.main) .sink(receiveValue: { [weak self] _ in self?.invalidateIntrinsicContentSize() diff --git a/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell.swift b/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell.swift index f8d494028..b2361ffc5 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell.swift @@ -76,8 +76,7 @@ extension StatusThreadRootTableViewCell { statusView.contentMetaText.textView.isAccessibilityElement = true statusView.contentMetaText.textView.isSelectable = true - statusView.viewModel - .$translation + statusView.viewModel.$translation .receive(on: DispatchQueue.main) .sink(receiveValue: { [weak self] _ in self?.invalidateIntrinsicContentSize() diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Status+Translate.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Status+Translate.swift index 483f52431..3289b9b81 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Status+Translate.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Status+Translate.swift @@ -19,12 +19,14 @@ extension APIService { ) async throws -> Mastodon.Response.Content { let domain = authenticationBox.domain let authorization = authenticationBox.userAuthorization + let targetLanguage = Bundle.main.preferredLocalizations.first let response = try await Mastodon.API.Statuses.translate( session: session, domain: domain, statusID: statusID, - authorization: authorization + authorization: authorization, + targetLanguage: targetLanguage ).singleOutput() return response diff --git a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Statuses+Translate.swift b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Statuses+Translate.swift index c3e790b67..b9d947ea7 100644 --- a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Statuses+Translate.swift +++ b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Statuses+Translate.swift @@ -16,7 +16,11 @@ extension Mastodon.API.Statuses { .appendingPathComponent(statusID) .appendingPathComponent("translate") } - + + public struct TranslateQuery: Codable, PostQuery { + public let lang: String + } + /// Translate Status /// /// Translate a given Status. @@ -31,11 +35,21 @@ extension Mastodon.API.Statuses { session: URLSession, domain: String, statusID: Mastodon.Entity.Status.ID, - authorization: Mastodon.API.OAuth.Authorization? - ) -> AnyPublisher, Error> { + authorization: Mastodon.API.OAuth.Authorization?, + targetLanguage: String? + ) -> AnyPublisher, Error> { + + let query: TranslateQuery? + + if let targetLanguage { + query = TranslateQuery(lang: targetLanguage) + } else { + query = nil + } + let request = Mastodon.API.post( url: translateEndpointURL(domain: domain, statusID: statusID), - query: nil, + query: query, authorization: authorization ) return session.dataTaskPublisher(for: request)