Browse Source

fix translating polls and spoilers (#4344)

The docs are wrong https://github.com/mastodon/documentation/pull/1423 🙄
pull/4350/head
Konrad Pozniak 2 years ago committed by GitHub
parent
commit
b022767ae6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      app/src/main/java/com/keylesspalace/tusky/entity/Translation.kt
  2. 6
      app/src/main/java/com/keylesspalace/tusky/viewdata/StatusViewData.kt

14
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<String>?,
@SerializedName("spoiler_text")
val spoilerText: String?,
val poll: TranslatedPoll?,
@SerializedName("media_attachments")
val mediaAttachments: List<MediaTranslation>,
@SerializedName("detected_source_language")
val detectedSourceLanguage: String,
val provider: String,
)
data class TranslatedPoll(
val options: List<TranslatedPollOption>
)
data class TranslatedPollOption(
val title: String
)

6
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)
}

Loading…
Cancel
Save