Resolve #359 Optional Missing Alt-Text warning (#1895)

* Resolve #359 Optional Missing Alt-Text warning

Add toggle in settings to require alt text (default off)
If setting is enabled, posting show an error if any attached media is missing alt text

* Re-localized strings
This commit is contained in:
Le-Roy Karunaratne 2024-01-21 21:28:03 -08:00 committed by GitHub
parent 13af2d7e3f
commit ed9a4a598d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 286 additions and 1 deletions

View File

@ -59,6 +59,7 @@ struct ContentSettingsView: View {
userPreferences.appAutoExpandMedia = userPreferences.autoExpandMedia
userPreferences.appDefaultPostsSensitive = userPreferences.postIsSensitive
userPreferences.appDefaultPostVisibility = userPreferences.postVisibility
userPreferences.appRequireAltText = userPreferences.appRequireAltText
}
}
@ -112,6 +113,10 @@ struct ContentSettingsView: View {
Text("settings.content.default-sensitive")
}
.disabled(userPreferences.useInstanceContentSettings)
Toggle(isOn: $userPreferences.appRequireAltText) {
Text("settings.content.require-alt-text")
}
}
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)

View File

@ -41561,6 +41561,124 @@
}
}
},
"settings.content.require-alt-text" : {
"localizations" : {
"be" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"ca" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"en-GB" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"eu" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"it" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"nb" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"nl" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"pl" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"tr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"uk" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "Require Alt Text to Post"
}
}
}
},
"settings.content.sharing" : {
"localizations" : {
"be" : {
@ -66055,6 +66173,125 @@
}
}
},
"status.error.no-alt-text" : {
"extractionState" : "manual",
"localizations" : {
"be" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"ca" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"en-GB" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"eu" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"it" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"nb" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"nl" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"pl" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"tr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"uk" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "Your settings require alt text on all media before posting"
}
}
}
},
"status.error.posting.title" : {
"extractionState" : "manual",
"localizations" : {
@ -76320,4 +76557,4 @@
}
},
"version" : "1.0"
}
}

View File

@ -22,6 +22,7 @@ import SwiftUI
@AppStorage("app_default_post_visibility") public var appDefaultPostVisibility: Models.Visibility = .pub
@AppStorage("app_default_reply_visibility") public var appDefaultReplyVisibility: Models.Visibility = .pub
@AppStorage("app_default_posts_sensitive") public var appDefaultPostsSensitive = false
@AppStorage("app_require_alt_text") public var appRequireAltText = false
@AppStorage("autoplay_video") public var autoPlayVideo = true
@AppStorage("mute_video") public var muteVideo = true
@AppStorage("always_use_deepl") public var alwaysUseDeepl = false
@ -163,6 +164,12 @@ import SwiftUI
storage.appDefaultPostsSensitive = appDefaultPostsSensitive
}
}
public var appRequireAltText: Bool {
didSet {
storage.appRequireAltText = appRequireAltText
}
}
public var autoPlayVideo: Bool {
didSet {
@ -466,6 +473,7 @@ import SwiftUI
appDefaultPostVisibility = storage.appDefaultPostVisibility
appDefaultReplyVisibility = storage.appDefaultReplyVisibility
appDefaultPostsSensitive = storage.appDefaultPostsSensitive
appRequireAltText = storage.appRequireAltText
autoPlayVideo = storage.autoPlayVideo
alwaysUseDeepl = storage.alwaysUseDeepl
userDeeplAPIFree = storage.userDeeplAPIFree

View File

@ -0,0 +1,15 @@
import Foundation
public enum PostError: Error {
// Throw when any attached media is missing media description (alt text)
case missingAltText
}
extension PostError: CustomStringConvertible {
public var description: String {
switch self {
case .missingAltText:
return NSLocalizedString("status.error.no-alt-text", comment: "media does not have media description")
}
}
}

View File

@ -130,6 +130,18 @@ extension StatusEditor {
var shouldDisablePollButton: Bool {
!mediaContainers.isEmpty
}
var allMediaHasDescription: Bool {
var everyMediaHasAltText: Bool = true;
mediaContainers.forEach { mediaContainer in
if (((mediaContainer.mediaAttachment?.description) == nil) ||
mediaContainer.mediaAttachment?.description?.count == 0) {
everyMediaHasAltText = false
}
}
return everyMediaHasAltText;
}
var shouldDisplayDismissWarning: Bool {
var modifiedStatusText = statusText.string.trimmingCharacters(in: .whitespaces)
@ -188,6 +200,10 @@ extension StatusEditor {
func postStatus() async -> Status? {
guard let client else { return nil }
do {
if (!allMediaHasDescription && UserPreferences.shared.appRequireAltText) {
throw PostError.missingAltText
}
if postingTimer == nil {
Timer.scheduledTimer(withTimeInterval: 0.05, repeats: true) { timer in
Task { @MainActor in
@ -250,6 +266,10 @@ extension StatusEditor {
postingError = error.error
showPostingErrorAlert = true
}
if let postError = error as? PostError {
postingError = postError.description
showPostingErrorAlert = true
}
isPosting = false
HapticManager.shared.fireHaptic(.notification(.error))
return nil