Widget localization

This commit is contained in:
Stuart Breckenridge
2020-11-21 09:11:31 +08:00
parent a18491b037
commit ee4ab43a8b
8 changed files with 147 additions and 19 deletions

View File

@@ -0,0 +1,70 @@
// swiftlint:disable all
// Generated using SwiftGen https://github.com/SwiftGen/SwiftGen
import Foundation
// swiftlint:disable superfluous_disable_command file_length implicit_return
// MARK: - Strings
// swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length
// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces
internal enum L10n {
/// A count of your smart feeds.
internal static let smartFeedSummaryWidgetDescription = L10n.tr("Localizable", "SmartFeedSummary_Widget_Description")
/// Your Smart Feed Summary
internal static let smartFeedSummaryWidgetTitle = L10n.tr("Localizable", "SmartFeedSummary_Widget_Title")
/// A sneak peak at your starred articles.
internal static let starredWidgetDescription = L10n.tr("Localizable", "Starred_Widget_Description")
/// You've not starred any artices.
internal static let starredWidgetNoItems = L10n.tr("Localizable", "Starred_Widget_NoItems")
/// Your Starred Articles
internal static let starredWidgetTitle = L10n.tr("Localizable", "Starred_Widget_Title")
/// Plural format key: "%#@starred_count@"
internal static func starredCount(_ p1: Int) -> String {
return L10n.tr("Localizable", "StarredCount", p1)
}
/// A sneak peak at recently published unread articles.
internal static let todayWidgetDescription = L10n.tr("Localizable", "Today_Widget_Description")
/// There are no recent articles to read.
internal static let todayWidgetNoItems = L10n.tr("Localizable", "Today_Widget_NoItems")
/// Your Today Articles
internal static let todayWidgetTitle = L10n.tr("Localizable", "Today_Widget_Title")
/// Plural format key: "%#@today_count@"
internal static func todayCount(_ p1: Int) -> String {
return L10n.tr("Localizable", "TodayCount", p1)
}
/// A sneak peak at your unread articles.
internal static let unreadWidgetDescription = L10n.tr("Localizable", "Unread_Widget_Description")
/// There's nothing to read right now.
internal static let unreadWidgetNoItems = L10n.tr("Localizable", "Unread_Widget_NoItems")
/// Your Unread Articles
internal static let unreadWidgetTitle = L10n.tr("Localizable", "Unread_Widget_Title")
/// Plural format key: "%#@unread_count@"
internal static func unreadCount(_ p1: Int) -> String {
return L10n.tr("Localizable", "UnreadCount", p1)
}
}
// swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length
// swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces
// MARK: - Implementation Details
extension L10n {
private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
let format = BundleToken.bundle.localizedString(forKey: key, value: nil, table: table)
return String(format: format, locale: Locale.current, arguments: args)
}
}
// swiftlint:disable convenience_type
private final class BundleToken {
static let bundle: Bundle = {
#if SWIFT_PACKAGE
return Bundle.module
#else
return Bundle(for: BundleToken.self)
#endif
}()
}
// swiftlint:enable convenience_type

View File

@@ -0,0 +1,29 @@
/*
Localizable.strings
NetNewsWire
Created by Stuart Breckenridge on 21/11/2020.
Copyright © 2020 Ranchero Software. All rights reserved.
*/
/* Bundle */
"Unread_Widget_Title" = "Your Unread Articles";
"Unread_Widget_Description" = "A sneak peak at your unread articles.";
"Today_Widget_Title" = "Your Today Articles";
"Today_Widget_Description" = "A sneak peak at recently published unread articles.";
"Starred_Widget_Title" = "Your Starred Articles";
"Starred_Widget_Description" = "A sneak peak at your starred articles.";
"SmartFeedSummary_Widget_Title" = "Your Smart Feed Summary";
"SmartFeedSummary_Widget_Description" = "A count of your smart feeds.";
/* Unread Widget */
"Unread_Widget_NoItems" = "There's nothing to read right now.";
/* Today Widget */
"Today_Widget_NoItems" = "There are no recent articles to read.";
/* Starred Widget */
"Starred_Widget_NoItems" = "You've not starred any artices.";

View File

@@ -69,9 +69,7 @@ struct StarredWidgetView : View {
count = count - 3
}
if count < 0 { count = 0 }
let formatString = NSLocalizedString("StarredCount",
comment: "Starred Count Format")
let str = String.localizedStringWithFormat(formatString, UInt(count))
let str = L10n.unreadCount(count)
return Text(str)
.font(.caption2)
.bold()

View File

@@ -69,9 +69,7 @@ struct TodayWidgetView : View {
count = count - 3
}
if count < 0 { count = 0 }
let formatString = NSLocalizedString("TodayCount",
comment: "Today Count Format")
let str = String.localizedStringWithFormat(formatString, UInt(count))
let str = L10n.unreadCount(count)
return Text(str)
.font(.caption2)
.bold()

View File

@@ -69,9 +69,7 @@ struct UnreadWidgetView : View {
count = count - 3
}
if count < 0 { count = 0 }
let formatString = NSLocalizedString("UnreadCount",
comment: "Unread Count Format")
let str = String.localizedStringWithFormat(formatString, UInt(count))
let str = L10n.unreadCount(count)
return Text(str)
.font(.caption2)
.bold()
@@ -99,7 +97,7 @@ struct UnreadWidgetView : View {
.frame(width: 15, height: 15, alignment: .center)
.cornerRadius(4)
Text("There's nothing to read right now.")
Text(L10n.unreadWidgetNoItems)
.font(.caption2)
.foregroundColor(.gray)
}

View File

@@ -22,8 +22,8 @@ struct UnreadWidget: Widget {
.background(Color("WidgetBackground"))
})
.configurationDisplayName("Your Unread Articles")
.description("A sneak peak at what's left unread.")
.configurationDisplayName(L10n.unreadWidgetTitle)
.description(L10n.unreadWidgetDescription)
.supportedFamilies([.systemMedium, .systemLarge])
}
@@ -40,8 +40,8 @@ struct TodayWidget: Widget {
.background(Color("WidgetBackground"))
})
.configurationDisplayName("Your Today Articles")
.description("A sneak peak at unread recently published articles.")
.configurationDisplayName(L10n.todayWidgetTitle)
.description(L10n.todayWidgetDescription)
.supportedFamilies([.systemMedium, .systemLarge])
}
@@ -58,8 +58,8 @@ struct StarredWidget: Widget {
.background(Color("WidgetBackground"))
})
.configurationDisplayName("Your Starred Articles")
.description("A sneak peak at your starred articles.")
.configurationDisplayName(L10n.starredWidgetTitle)
.description(L10n.starredWidgetDescription)
.supportedFamilies([.systemMedium, .systemLarge])
}
@@ -76,8 +76,8 @@ struct SmartFeedSummaryWidget: Widget {
.background(Color("WidgetBackground"))
})
.configurationDisplayName("Your Smart Feed Summary")
.description("A count of your smart feeds.")
.configurationDisplayName(L10n.smartFeedSummaryWidgetTitle)
.description(L10n.smartFeedSummaryWidgetDescription)
.supportedFamilies([.systemSmall])
}