Send the device-language to translate-endpoint
This commit is contained in:
parent
3850c24b93
commit
c3ef66aeaa
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -17,6 +17,10 @@ extension Mastodon.API.Statuses {
|
|||
.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?
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue