From bd1f7af036323c490042ceeacc53b0ad0ea81639 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Mon, 31 Aug 2020 12:39:26 -0700 Subject: [PATCH] Move all localization to views --- View Models/EditFilterViewModel.swift | 19 ------------------- View Models/TabNavigationViewModel.swift | 15 --------------- Views/EditFilterView.swift | 19 +++++++++++++++++++ Views/TabNavigationView.swift | 23 ++++++++++++++++++++--- 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/View Models/EditFilterViewModel.swift b/View Models/EditFilterViewModel.swift index e1f953a..1f08b7c 100644 --- a/View Models/EditFilterViewModel.swift +++ b/View Models/EditFilterViewModel.swift @@ -58,22 +58,3 @@ extension EditFilterViewModel { .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: "") - } - } -} diff --git a/View Models/TabNavigationViewModel.swift b/View Models/TabNavigationViewModel.swift index 2f2fd18..e6db9c4 100644 --- a/View Models/TabNavigationViewModel.swift +++ b/View Models/TabNavigationViewModel.swift @@ -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 { switch timeline { case .home: return "house" diff --git a/Views/EditFilterView.swift b/Views/EditFilterView.swift index 60f6b3e..711fc74 100644 --- a/Views/EditFilterView.swift +++ b/Views/EditFilterView.swift @@ -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 struct EditFilterView_Previews: PreviewProvider { static var previews: some View { diff --git a/Views/TabNavigationView.swift b/Views/TabNavigationView.swift index 133a60d..da19148 100644 --- a/Views/TabNavigationView.swift +++ b/Views/TabNavigationView.swift @@ -43,11 +43,11 @@ private extension TabNavigationView { StatusListView(viewModel: viewModel.viewModel(timeline: viewModel.timeline)) .id(viewModel.timeline.id) .edgesIgnoringSafeArea(.all) - .navigationBarTitle(viewModel.title(timeline: viewModel.timeline), displayMode: .inline) + .navigationBarTitle(timelineTitle, displayMode: .inline) .toolbar { ToolbarItem(placement: .principal) { VStack { - Text(viewModel.title(timeline: viewModel.timeline)) + Text(timelineTitle) .font(.headline) Text(viewModel.timelineSubtitle) .font(.footnote) @@ -62,7 +62,7 @@ private extension TabNavigationView { Button { viewModel.timeline = timeline } label: { - Label(viewModel.title(timeline: timeline), + Label(timelineTitle, 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 struct TabNavigation_Previews: PreviewProvider { static var previews: some View {