mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 08:10:59 +00:00
Localized title
This commit is contained in:
parent
acfd127672
commit
a6d959a6b9
8 changed files with 41 additions and 3 deletions
|
@ -1,10 +1,12 @@
|
||||||
// Copyright © 2020 Metabolist. All rights reserved.
|
// Copyright © 2020 Metabolist. All rights reserved.
|
||||||
|
|
||||||
|
"account.%@-followers" = "%@'s Followers";
|
||||||
"account.block" = "Block";
|
"account.block" = "Block";
|
||||||
"account.field.verified" = "Verified %@";
|
"account.field.verified" = "Verified %@";
|
||||||
"account.follow" = "Follow";
|
"account.follow" = "Follow";
|
||||||
"account.following" = "Following";
|
"account.following" = "Following";
|
||||||
"account.following-count" = "%ld Following";
|
"account.following-count" = "%ld Following";
|
||||||
|
"account.followed-by-%@" = "Followed by %@";
|
||||||
"account.hide-reblogs" = "Hide boosts";
|
"account.hide-reblogs" = "Hide boosts";
|
||||||
"account.mute" = "Mute";
|
"account.mute" = "Mute";
|
||||||
"account.request" = "Request";
|
"account.request" = "Request";
|
||||||
|
|
|
@ -15,13 +15,18 @@ public struct AccountListService {
|
||||||
private let endpoint: AccountsEndpoint
|
private let endpoint: AccountsEndpoint
|
||||||
private let mastodonAPIClient: MastodonAPIClient
|
private let mastodonAPIClient: MastodonAPIClient
|
||||||
private let contentDatabase: ContentDatabase
|
private let contentDatabase: ContentDatabase
|
||||||
|
private let titleComponents: [String]?
|
||||||
private let nextPageMaxIdSubject = PassthroughSubject<String, Never>()
|
private let nextPageMaxIdSubject = PassthroughSubject<String, Never>()
|
||||||
|
|
||||||
init(endpoint: AccountsEndpoint, mastodonAPIClient: MastodonAPIClient, contentDatabase: ContentDatabase) {
|
init(endpoint: AccountsEndpoint,
|
||||||
|
mastodonAPIClient: MastodonAPIClient,
|
||||||
|
contentDatabase: ContentDatabase,
|
||||||
|
titleComponents: [String]? = nil) {
|
||||||
list = AccountList()
|
list = AccountList()
|
||||||
self.endpoint = endpoint
|
self.endpoint = endpoint
|
||||||
self.mastodonAPIClient = mastodonAPIClient
|
self.mastodonAPIClient = mastodonAPIClient
|
||||||
self.contentDatabase = contentDatabase
|
self.contentDatabase = contentDatabase
|
||||||
|
self.titleComponents = titleComponents
|
||||||
sections = contentDatabase.accountListPublisher(list)
|
sections = contentDatabase.accountListPublisher(list)
|
||||||
.map { [$0.map(CollectionItem.account)] }
|
.map { [$0.map(CollectionItem.account)] }
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
|
@ -41,4 +46,12 @@ extension AccountListService: CollectionService {
|
||||||
.flatMap { contentDatabase.append(accounts: $0.result, toList: list) }
|
.flatMap { contentDatabase.append(accounts: $0.result, toList: list) }
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var titleLocalizationComponents: AnyPublisher<[String], Never> {
|
||||||
|
if let titleComponents = titleComponents {
|
||||||
|
return Just(titleComponents).eraseToAnyPublisher()
|
||||||
|
} else {
|
||||||
|
return Empty().eraseToAnyPublisher()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,14 +95,16 @@ public extension AccountService {
|
||||||
AccountListService(
|
AccountListService(
|
||||||
endpoint: .accountsFollowing(id: account.id),
|
endpoint: .accountsFollowing(id: account.id),
|
||||||
mastodonAPIClient: mastodonAPIClient,
|
mastodonAPIClient: mastodonAPIClient,
|
||||||
contentDatabase: contentDatabase)
|
contentDatabase: contentDatabase,
|
||||||
|
titleComponents: ["account.followed-by-%@", "@".appending(account.acct)])
|
||||||
}
|
}
|
||||||
|
|
||||||
func followersService() -> AccountListService {
|
func followersService() -> AccountListService {
|
||||||
AccountListService(
|
AccountListService(
|
||||||
endpoint: .accountsFollowers(id: account.id),
|
endpoint: .accountsFollowers(id: account.id),
|
||||||
mastodonAPIClient: mastodonAPIClient,
|
mastodonAPIClient: mastodonAPIClient,
|
||||||
contentDatabase: contentDatabase)
|
contentDatabase: contentDatabase,
|
||||||
|
titleComponents: ["account.%@-followers", "@".appending(account.acct)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ public protocol CollectionService {
|
||||||
var sections: AnyPublisher<[[CollectionItem]], Error> { get }
|
var sections: AnyPublisher<[[CollectionItem]], Error> { get }
|
||||||
var nextPageMaxId: AnyPublisher<String, Never> { get }
|
var nextPageMaxId: AnyPublisher<String, Never> { get }
|
||||||
var title: AnyPublisher<String, Never> { get }
|
var title: AnyPublisher<String, Never> { get }
|
||||||
|
var titleLocalizationComponents: AnyPublisher<[String], Never> { get }
|
||||||
var navigationService: NavigationService { get }
|
var navigationService: NavigationService { get }
|
||||||
var markerTimeline: Marker.Timeline? { get }
|
var markerTimeline: Marker.Timeline? { get }
|
||||||
func request(maxId: String?, minId: String?) -> AnyPublisher<Never, Error>
|
func request(maxId: String?, minId: String?) -> AnyPublisher<Never, Error>
|
||||||
|
@ -17,5 +18,7 @@ extension CollectionService {
|
||||||
|
|
||||||
public var title: AnyPublisher<String, Never> { Empty().eraseToAnyPublisher() }
|
public var title: AnyPublisher<String, Never> { Empty().eraseToAnyPublisher() }
|
||||||
|
|
||||||
|
public var titleLocalizationComponents: AnyPublisher<[String], Never> { Empty().eraseToAnyPublisher() }
|
||||||
|
|
||||||
public var markerTimeline: Marker.Timeline? { nil }
|
public var markerTimeline: Marker.Timeline? { nil }
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,6 +228,15 @@ private extension TableViewController {
|
||||||
func setupViewModelBindings() {
|
func setupViewModelBindings() {
|
||||||
viewModel.title.sink { [weak self] in self?.navigationItem.title = $0 }.store(in: &cancellables)
|
viewModel.title.sink { [weak self] in self?.navigationItem.title = $0 }.store(in: &cancellables)
|
||||||
|
|
||||||
|
viewModel.titleLocalizationComponents.sink { [weak self] in
|
||||||
|
guard let key = $0.first else { return }
|
||||||
|
|
||||||
|
self?.navigationItem.title = String(
|
||||||
|
format: NSLocalizedString(key, comment: ""),
|
||||||
|
arguments: Array($0.suffix(from: 1)))
|
||||||
|
}
|
||||||
|
.store(in: &cancellables)
|
||||||
|
|
||||||
viewModel.updates.sink { [weak self] in self?.update($0) }.store(in: &cancellables)
|
viewModel.updates.sink { [weak self] in self?.update($0) }.store(in: &cancellables)
|
||||||
|
|
||||||
viewModel.events.receive(on: DispatchQueue.main)
|
viewModel.events.receive(on: DispatchQueue.main)
|
||||||
|
|
|
@ -66,6 +66,10 @@ extension CollectionItemsViewModel: CollectionViewModel {
|
||||||
|
|
||||||
public var title: AnyPublisher<String, Never> { collectionService.title }
|
public var title: AnyPublisher<String, Never> { collectionService.title }
|
||||||
|
|
||||||
|
public var titleLocalizationComponents: AnyPublisher<[String], Never> {
|
||||||
|
collectionService.titleLocalizationComponents
|
||||||
|
}
|
||||||
|
|
||||||
public var expandAll: AnyPublisher<ExpandAllState, Never> {
|
public var expandAll: AnyPublisher<ExpandAllState, Never> {
|
||||||
expandAllSubject.eraseToAnyPublisher()
|
expandAllSubject.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import Foundation
|
||||||
public protocol CollectionViewModel {
|
public protocol CollectionViewModel {
|
||||||
var updates: AnyPublisher<CollectionUpdate, Never> { get }
|
var updates: AnyPublisher<CollectionUpdate, Never> { get }
|
||||||
var title: AnyPublisher<String, Never> { get }
|
var title: AnyPublisher<String, Never> { get }
|
||||||
|
var titleLocalizationComponents: AnyPublisher<[String], Never> { get }
|
||||||
var expandAll: AnyPublisher<ExpandAllState, Never> { get }
|
var expandAll: AnyPublisher<ExpandAllState, Never> { get }
|
||||||
var alertItems: AnyPublisher<AlertItem, Never> { get }
|
var alertItems: AnyPublisher<AlertItem, Never> { get }
|
||||||
var loading: AnyPublisher<Bool, Never> { get }
|
var loading: AnyPublisher<Bool, Never> { get }
|
||||||
|
|
|
@ -70,6 +70,10 @@ extension ProfileViewModel: CollectionViewModel {
|
||||||
$accountViewModel.compactMap { $0?.accountName }.eraseToAnyPublisher()
|
$accountViewModel.compactMap { $0?.accountName }.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var titleLocalizationComponents: AnyPublisher<[String], Never> {
|
||||||
|
collectionViewModel.flatMap(\.titleLocalizationComponents).eraseToAnyPublisher()
|
||||||
|
}
|
||||||
|
|
||||||
public var expandAll: AnyPublisher<ExpandAllState, Never> {
|
public var expandAll: AnyPublisher<ExpandAllState, Never> {
|
||||||
Empty().eraseToAnyPublisher()
|
Empty().eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue