From b022767ae6740efa367cf64c953e767d98fac212 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Fri, 29 Mar 2024 21:13:57 +0100 Subject: [PATCH] fix translating polls and spoilers (#4344) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The docs are wrong https://github.com/mastodon/documentation/pull/1423 🙄 --- .../com/keylesspalace/tusky/entity/Translation.kt | 14 +++++++++++--- .../keylesspalace/tusky/viewdata/StatusViewData.kt | 6 ++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/entity/Translation.kt b/app/src/main/java/com/keylesspalace/tusky/entity/Translation.kt index 1eee91d9..e767556c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/entity/Translation.kt +++ b/app/src/main/java/com/keylesspalace/tusky/entity/Translation.kt @@ -14,12 +14,20 @@ data class MediaTranslation( */ data class Translation( val content: String, - @SerializedName("spoiler_warning") - val spoilerWarning: String?, - val poll: List?, + @SerializedName("spoiler_text") + val spoilerText: String?, + val poll: TranslatedPoll?, @SerializedName("media_attachments") val mediaAttachments: List, @SerializedName("detected_source_language") val detectedSourceLanguage: String, val provider: String, ) + +data class TranslatedPoll( + val options: List +) + +data class TranslatedPollOption( + val title: String +) diff --git a/app/src/main/java/com/keylesspalace/tusky/viewdata/StatusViewData.kt b/app/src/main/java/com/keylesspalace/tusky/viewdata/StatusViewData.kt index f25d82e4..6f8d5d69 100644 --- a/app/src/main/java/com/keylesspalace/tusky/viewdata/StatusViewData.kt +++ b/app/src/main/java/com/keylesspalace/tusky/viewdata/StatusViewData.kt @@ -67,10 +67,12 @@ sealed class StatusViewData { actionable.attachments.translated { translation -> map { it.translated(translation) } } val spoilerText: String = - actionable.spoilerText.translated { translation -> translation.spoilerWarning ?: this } + actionable.spoilerText.translated { translation -> translation.spoilerText ?: this } val poll = actionable.poll?.translated { translation -> - val translatedOptionsText = translation.poll ?: return@translated this + val translatedOptionsText = translation.poll?.options?.map { option -> + option.title + } ?: return@translated this val translatedOptions = options.zip(translatedOptionsText) { option, translatedText -> option.copy(title = translatedText) }