diff --git a/Localization/app.json b/Localization/app.json index 36275e994..c58b8798d 100644 --- a/Localization/app.json +++ b/Localization/app.json @@ -875,6 +875,16 @@ "configuration": { "display_name": "Hashtag", "description": "Shows a recent status with the selected hashtag." + }, + "not_found": { + "account_name": "John Mastodon", + "account": "@johnMastodon@no-such.account", + "content": "Sorry, we didn't find a status with #%@. Please try a #DifferentHashtag or check the Widget-settings." + }, + "placeholder": { + "account_name": "John Mastodon", + "account": "@johnMastodon@no-such.account", + "content": "This is how a status with a #hashtag would look like. Of course you can decide about the #hashtag" } } } diff --git a/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift b/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift index fb0b497c3..4131a6bab 100644 --- a/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift +++ b/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift @@ -1550,6 +1550,24 @@ public enum L10n { /// Hashtag public static let displayName = L10n.tr("Localizable", "Widget.Hashtag.Configuration.DisplayName", fallback: "Hashtag") } + public enum NotFound { + /// @johnMastodon@no-such.account + public static let account = L10n.tr("Localizable", "Widget.Hashtag.NotFound.Account", fallback: "@johnMastodon@no-such.account") + /// John Mastodon + public static let accountName = L10n.tr("Localizable", "Widget.Hashtag.NotFound.AccountName", fallback: "John Mastodon") + /// Sorry, we didn't find a status with #%@. Please try a #DifferentHashtag or check the Widget-settings. + public static func content(_ p1: Any) -> String { + return L10n.tr("Localizable", "Widget.Hashtag.NotFound.Content", String(describing: p1), fallback: "Sorry, we didn't find a status with #%@. Please try a #DifferentHashtag or check the Widget-settings.") + } + } + public enum Placeholder { + /// @johnMastodon@no-such.account + public static let account = L10n.tr("Localizable", "Widget.Hashtag.Placeholder.Account", fallback: "@johnMastodon@no-such.account") + /// John Mastodon + public static let accountName = L10n.tr("Localizable", "Widget.Hashtag.Placeholder.AccountName", fallback: "John Mastodon") + /// This is how a status with a #hashtag would look like. Of course you can decide about the #hashtag + public static let content = L10n.tr("Localizable", "Widget.Hashtag.Placeholder.Content", fallback: "This is how a status with a #hashtag would look like. Of course you can decide about the #hashtag") + } } public enum LatestFollowers { /// Show latest followers. diff --git a/MastodonSDK/Sources/MastodonLocalization/Resources/Base.lproj/Localizable.strings b/MastodonSDK/Sources/MastodonLocalization/Resources/Base.lproj/Localizable.strings index 6f7d0c8f4..df3e00d39 100644 --- a/MastodonSDK/Sources/MastodonLocalization/Resources/Base.lproj/Localizable.strings +++ b/MastodonSDK/Sources/MastodonLocalization/Resources/Base.lproj/Localizable.strings @@ -545,3 +545,11 @@ uploaded to Mastodon."; "Widget.MultipleFollowers.MockUser.DisplayName" = "Another follower"; "Widget.Hashtag.Configuration.Description" = "Shows a recent status with the selected hashtag"; "Widget.Hashtag.Configuration.DisplayName" = "Hashtag"; + +"Widget.Hashtag.NotFound.AccountName" = "John Mastodon"; +"Widget.Hashtag.NotFound.Account" = "@johnMastodon@no-such.account"; +"Widget.Hashtag.NotFound.Content" = "Sorry, we didn't find a status with #%@. Please try a #DifferentHashtag or check the Widget-settings."; + +"Widget.Hashtag.Placeholder.AccountName" = "John Mastodon"; +"Widget.Hashtag.Placeholder.Account" = "@johnMastodon@no-such.account"; +"Widget.Hashtag.Placeholder.Content" = "This is how a status with a #hashtag would look like. Of course you can decide about the #hashtag"; diff --git a/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings b/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings index 6f7d0c8f4..df3e00d39 100644 --- a/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings +++ b/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings @@ -545,3 +545,11 @@ uploaded to Mastodon."; "Widget.MultipleFollowers.MockUser.DisplayName" = "Another follower"; "Widget.Hashtag.Configuration.Description" = "Shows a recent status with the selected hashtag"; "Widget.Hashtag.Configuration.DisplayName" = "Hashtag"; + +"Widget.Hashtag.NotFound.AccountName" = "John Mastodon"; +"Widget.Hashtag.NotFound.Account" = "@johnMastodon@no-such.account"; +"Widget.Hashtag.NotFound.Content" = "Sorry, we didn't find a status with #%@. Please try a #DifferentHashtag or check the Widget-settings."; + +"Widget.Hashtag.Placeholder.AccountName" = "John Mastodon"; +"Widget.Hashtag.Placeholder.Account" = "@johnMastodon@no-such.account"; +"Widget.Hashtag.Placeholder.Content" = "This is how a status with a #hashtag would look like. Of course you can decide about the #hashtag"; diff --git a/WidgetExtension/Variants/Hashtag/HashtagWidget.swift b/WidgetExtension/Variants/Hashtag/HashtagWidget.swift index 28566e10f..22162f9a1 100644 --- a/WidgetExtension/Variants/Hashtag/HashtagWidget.swift +++ b/WidgetExtension/Variants/Hashtag/HashtagWidget.swift @@ -37,14 +37,15 @@ extension HashtagWidgetProvider { } } - Task { - let desiredHashtag: String + let desiredHashtag: String - if let hashtag = configuration.hashtag { - desiredHashtag = hashtag - } else { - return completion(.notFound) - } + if let hashtag = configuration.hashtag { + desiredHashtag = hashtag + } else { + return completion(.notFound("hashtag")) + } + + Task { do { let mostRecentStatuses = try await WidgetExtension.appContext @@ -78,12 +79,12 @@ extension HashtagWidgetProvider { completion(hashtagTimelineEntry) } else { - let noStatusFound = HashtagWidgetTimelineEntry.notFound + let noStatusFound = HashtagWidgetTimelineEntry.notFound(desiredHashtag) completion(noStatusFound) } } catch { - completion(.notFound) + completion(.notFound(desiredHashtag)) } } @@ -97,31 +98,30 @@ struct HashtagWidgetTimelineEntry: TimelineEntry { var hashtag: HashtagEntry static var placeholder: Self { - //TODO: @zeitschlag Add Localization HashtagWidgetTimelineEntry( date: .now, hashtag: HashtagEntry( - accountName: "John Mastodon", - account: "@johnmastodon@mastodon.social", - content: "Caturday is the best day of the week #CatsOfMastodon", + accountName: L10n.Widget.Hashtag.Placeholder.accountName, + account: L10n.Widget.Hashtag.Placeholder.account, + content: L10n.Widget.Hashtag.Placeholder.content, reblogCount: 13, favoriteCount: 12, - hashtag: "#CatsOfMastodon", - timestamp: .now.addingTimeInterval(-3600 * 18) + hashtag: "#hashtag", + timestamp: .now.addingTimeInterval(-3600 * 12) ) ) } - static var notFound: Self { + static func notFound(_ hashtag: String? = nil) -> Self { HashtagWidgetTimelineEntry( date: .now, hashtag: HashtagEntry( - accountName: "Not Found", - account: "404", - content: "Couldn't find a status, sorryyyyyyy", + accountName: L10n.Widget.Hashtag.NotFound.accountName, + account: L10n.Widget.Hashtag.NotFound.account, + content: L10n.Widget.Hashtag.NotFound.content(hashtag ?? "hashtag"), reblogCount: 0, favoriteCount: 0, - hashtag: "", + hashtag: hashtag ?? "", timestamp: .now ) )