Locale notfound/placeholder-texts (IOS-37)

This commit is contained in:
Nathan Mattes 2023-04-22 23:20:32 +02:00
parent 8b1316814a
commit 1829793ac5
5 changed files with 64 additions and 20 deletions

View File

@ -875,6 +875,16 @@
"configuration": { "configuration": {
"display_name": "Hashtag", "display_name": "Hashtag",
"description": "Shows a recent status with the selected 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 <a>#%@</a>. Please try a <a>#DifferentHashtag</a> or check the Widget-settings."
},
"placeholder": {
"account_name": "John Mastodon",
"account": "@johnMastodon@no-such.account",
"content": "This is how a status with a <a>#hashtag</a> would look like. Of course you can decide about the <a>#hashtag</a>"
} }
} }
} }

View File

@ -1550,6 +1550,24 @@ public enum L10n {
/// Hashtag /// Hashtag
public static let displayName = L10n.tr("Localizable", "Widget.Hashtag.Configuration.DisplayName", fallback: "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 <a>#%@</a>. Please try a <a>#DifferentHashtag</a> 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 <a>#%@</a>. Please try a <a>#DifferentHashtag</a> 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 <a>#hashtag</a> would look like. Of course you can decide about the <a>#hashtag</a>
public static let content = L10n.tr("Localizable", "Widget.Hashtag.Placeholder.Content", fallback: "This is how a status with a <a>#hashtag</a> would look like. Of course you can decide about the <a>#hashtag</a>")
}
} }
public enum LatestFollowers { public enum LatestFollowers {
/// Show latest followers. /// Show latest followers.

View File

@ -545,3 +545,11 @@ uploaded to Mastodon.";
"Widget.MultipleFollowers.MockUser.DisplayName" = "Another follower"; "Widget.MultipleFollowers.MockUser.DisplayName" = "Another follower";
"Widget.Hashtag.Configuration.Description" = "Shows a recent status with the selected hashtag"; "Widget.Hashtag.Configuration.Description" = "Shows a recent status with the selected hashtag";
"Widget.Hashtag.Configuration.DisplayName" = "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 <a>#%@</a>. Please try a <a>#DifferentHashtag</a> 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 <a>#hashtag</a> would look like. Of course you can decide about the <a>#hashtag</a>";

View File

@ -545,3 +545,11 @@ uploaded to Mastodon.";
"Widget.MultipleFollowers.MockUser.DisplayName" = "Another follower"; "Widget.MultipleFollowers.MockUser.DisplayName" = "Another follower";
"Widget.Hashtag.Configuration.Description" = "Shows a recent status with the selected hashtag"; "Widget.Hashtag.Configuration.Description" = "Shows a recent status with the selected hashtag";
"Widget.Hashtag.Configuration.DisplayName" = "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 <a>#%@</a>. Please try a <a>#DifferentHashtag</a> 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 <a>#hashtag</a> would look like. Of course you can decide about the <a>#hashtag</a>";

View File

@ -37,15 +37,16 @@ extension HashtagWidgetProvider {
} }
} }
Task {
let desiredHashtag: String let desiredHashtag: String
if let hashtag = configuration.hashtag { if let hashtag = configuration.hashtag {
desiredHashtag = hashtag desiredHashtag = hashtag
} else { } else {
return completion(.notFound) return completion(.notFound("hashtag"))
} }
Task {
do { do {
let mostRecentStatuses = try await WidgetExtension.appContext let mostRecentStatuses = try await WidgetExtension.appContext
.apiService .apiService
@ -78,12 +79,12 @@ extension HashtagWidgetProvider {
completion(hashtagTimelineEntry) completion(hashtagTimelineEntry)
} else { } else {
let noStatusFound = HashtagWidgetTimelineEntry.notFound let noStatusFound = HashtagWidgetTimelineEntry.notFound(desiredHashtag)
completion(noStatusFound) completion(noStatusFound)
} }
} catch { } catch {
completion(.notFound) completion(.notFound(desiredHashtag))
} }
} }
@ -97,31 +98,30 @@ struct HashtagWidgetTimelineEntry: TimelineEntry {
var hashtag: HashtagEntry var hashtag: HashtagEntry
static var placeholder: Self { static var placeholder: Self {
//TODO: @zeitschlag Add Localization
HashtagWidgetTimelineEntry( HashtagWidgetTimelineEntry(
date: .now, date: .now,
hashtag: HashtagEntry( hashtag: HashtagEntry(
accountName: "John Mastodon", accountName: L10n.Widget.Hashtag.Placeholder.accountName,
account: "@johnmastodon@mastodon.social", account: L10n.Widget.Hashtag.Placeholder.account,
content: "Caturday is the best day of the week #CatsOfMastodon", content: L10n.Widget.Hashtag.Placeholder.content,
reblogCount: 13, reblogCount: 13,
favoriteCount: 12, favoriteCount: 12,
hashtag: "#CatsOfMastodon", hashtag: "#hashtag",
timestamp: .now.addingTimeInterval(-3600 * 18) timestamp: .now.addingTimeInterval(-3600 * 12)
) )
) )
} }
static var notFound: Self { static func notFound(_ hashtag: String? = nil) -> Self {
HashtagWidgetTimelineEntry( HashtagWidgetTimelineEntry(
date: .now, date: .now,
hashtag: HashtagEntry( hashtag: HashtagEntry(
accountName: "Not Found", accountName: L10n.Widget.Hashtag.NotFound.accountName,
account: "404", account: L10n.Widget.Hashtag.NotFound.account,
content: "Couldn't find a status, sorryyyyyyy", content: L10n.Widget.Hashtag.NotFound.content(hashtag ?? "hashtag"),
reblogCount: 0, reblogCount: 0,
favoriteCount: 0, favoriteCount: 0,
hashtag: "", hashtag: hashtag ?? "",
timestamp: .now timestamp: .now
) )
) )