Send the device-language to translate-endpoint

This commit is contained in:
Nathan Mattes 2023-10-17 12:48:01 +02:00
parent 3850c24b93
commit c3ef66aeaa
4 changed files with 23 additions and 9 deletions

View File

@ -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()

View File

@ -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()

View File

@ -19,12 +19,14 @@ extension APIService {
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Translation> {
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

View File

@ -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<Mastodon.Response.Content<Mastodon.Entity.Translation>, Error> {
authorization: Mastodon.API.OAuth.Authorization?,
targetLanguage: String?
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Translation>, 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)