Move all localization to views

This commit is contained in:
Justin Mazzocchi 2020-08-31 12:39:26 -07:00
parent 96fdc6c837
commit bd1f7af036
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
4 changed files with 39 additions and 37 deletions

View file

@ -58,22 +58,3 @@ extension EditFilterViewModel {
.store(in: &cancellables) .store(in: &cancellables)
} }
} }
extension Filter.Context {
var localized: String {
switch self {
case .home:
return NSLocalizedString("filter.context.home", comment: "")
case .notifications:
return NSLocalizedString("filter.context.notifications", comment: "")
case .public:
return NSLocalizedString("filter.context.public", comment: "")
case .thread:
return NSLocalizedString("filter.context.thread", comment: "")
case .account:
return NSLocalizedString("filter.context.account", comment: "")
case .unknown:
return NSLocalizedString("filter.context.unknown", comment: "")
}
}
}

View file

@ -43,21 +43,6 @@ extension TabNavigationViewModel {
} }
} }
func title(timeline: Timeline) -> String {
switch timeline {
case .home:
return NSLocalizedString("timelines.home", comment: "")
case .local:
return NSLocalizedString("timelines.local", comment: "")
case .federated:
return NSLocalizedString("timelines.federated", comment: "")
case let .list(list):
return list.title
case let .tag(tag):
return "#" + tag
}
}
func systemImageName(timeline: Timeline) -> String { func systemImageName(timeline: Timeline) -> String {
switch timeline { switch timeline {
case .home: return "house" case .home: return "house"

View file

@ -76,6 +76,25 @@ struct EditFilterView: View {
} }
} }
extension Filter.Context {
var localized: String {
switch self {
case .home:
return NSLocalizedString("filter.context.home", comment: "")
case .notifications:
return NSLocalizedString("filter.context.notifications", comment: "")
case .public:
return NSLocalizedString("filter.context.public", comment: "")
case .thread:
return NSLocalizedString("filter.context.thread", comment: "")
case .account:
return NSLocalizedString("filter.context.account", comment: "")
case .unknown:
return NSLocalizedString("filter.context.unknown", comment: "")
}
}
}
#if DEBUG #if DEBUG
struct EditFilterView_Previews: PreviewProvider { struct EditFilterView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {

View file

@ -43,11 +43,11 @@ private extension TabNavigationView {
StatusListView(viewModel: viewModel.viewModel(timeline: viewModel.timeline)) StatusListView(viewModel: viewModel.viewModel(timeline: viewModel.timeline))
.id(viewModel.timeline.id) .id(viewModel.timeline.id)
.edgesIgnoringSafeArea(.all) .edgesIgnoringSafeArea(.all)
.navigationBarTitle(viewModel.title(timeline: viewModel.timeline), displayMode: .inline) .navigationBarTitle(timelineTitle, displayMode: .inline)
.toolbar { .toolbar {
ToolbarItem(placement: .principal) { ToolbarItem(placement: .principal) {
VStack { VStack {
Text(viewModel.title(timeline: viewModel.timeline)) Text(timelineTitle)
.font(.headline) .font(.headline)
Text(viewModel.timelineSubtitle) Text(viewModel.timelineSubtitle)
.font(.footnote) .font(.footnote)
@ -62,7 +62,7 @@ private extension TabNavigationView {
Button { Button {
viewModel.timeline = timeline viewModel.timeline = timeline
} label: { } label: {
Label(viewModel.title(timeline: timeline), Label(timelineTitle,
systemImage: viewModel.systemImageName(timeline: timeline)) systemImage: viewModel.systemImageName(timeline: timeline))
} }
} }
@ -101,6 +101,23 @@ private extension TabNavigationView {
} }
} }
private extension TabNavigationView {
var timelineTitle: String {
switch viewModel.timeline {
case .home:
return NSLocalizedString("timelines.home", comment: "")
case .local:
return NSLocalizedString("timelines.local", comment: "")
case .federated:
return NSLocalizedString("timelines.federated", comment: "")
case let .list(list):
return list.title
case let .tag(tag):
return "#" + tag
}
}
}
#if DEBUG #if DEBUG
struct TabNavigation_Previews: PreviewProvider { struct TabNavigation_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {