From e119a06bba9ecb3839a81e801f656c60ff7848a6 Mon Sep 17 00:00:00 2001 From: CMK Date: Tue, 17 May 2022 23:27:58 +0800 Subject: [PATCH] chore: using i18n strings --- .../FamiliarFollowersViewController.swift | 4 +++- .../Follower/FollowerListViewController.swift | 2 +- .../Following/FollowingListViewController.swift | 2 +- .../FavoritedBy/FavoritedByViewController.swift | 2 +- .../RebloggedBy/RebloggedByViewController.swift | 2 +- .../MastodonLocalization+Bundle.swift | 14 ++++++++++++++ ...iliarFollowersDashboardView+Configuration.swift | 2 +- .../FamiliarFollowersDashboardView+ViewModel.swift | 12 ++++++++---- .../View/Content/StatusView+ViewModel.swift | 5 ++--- 9 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 MastodonSDK/Sources/MastodonLocalization/MastodonLocalization+Bundle.swift diff --git a/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewController.swift b/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewController.swift index bb1f46c2..1e60f7a9 100644 --- a/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewController.swift +++ b/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewController.swift @@ -8,6 +8,7 @@ import os.log import UIKit import Combine +import MastodonLocalization final class FamiliarFollowersViewController: UIViewController, NeedsDependency { @@ -38,7 +39,8 @@ extension FamiliarFollowersViewController { override func viewDidLoad() { super.viewDidLoad() - title = "Followers you familiar" + title = L10n.Scene.Familiarfollowers.title + view.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemBackgroundColor ThemeService.shared.currentTheme .receive(on: DispatchQueue.main) diff --git a/Mastodon/Scene/Profile/Follower/FollowerListViewController.swift b/Mastodon/Scene/Profile/Follower/FollowerListViewController.swift index 1b9efa1f..decc1ee9 100644 --- a/Mastodon/Scene/Profile/Follower/FollowerListViewController.swift +++ b/Mastodon/Scene/Profile/Follower/FollowerListViewController.swift @@ -43,7 +43,7 @@ extension FollowerListViewController { override func viewDidLoad() { super.viewDidLoad() - title = L10n.Scene.Profile.Dashboard.followers + title = L10n.Scene.Follower.title view.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemBackgroundColor ThemeService.shared.currentTheme diff --git a/Mastodon/Scene/Profile/Following/FollowingListViewController.swift b/Mastodon/Scene/Profile/Following/FollowingListViewController.swift index eb087222..c125b021 100644 --- a/Mastodon/Scene/Profile/Following/FollowingListViewController.swift +++ b/Mastodon/Scene/Profile/Following/FollowingListViewController.swift @@ -43,7 +43,7 @@ extension FollowingListViewController { override func viewDidLoad() { super.viewDidLoad() - title = L10n.Scene.Profile.Dashboard.following + title = L10n.Scene.Following.title view.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemBackgroundColor ThemeService.shared.currentTheme diff --git a/Mastodon/Scene/Profile/UserLIst/FavoritedBy/FavoritedByViewController.swift b/Mastodon/Scene/Profile/UserLIst/FavoritedBy/FavoritedByViewController.swift index 7316be5a..0e2bc64e 100644 --- a/Mastodon/Scene/Profile/UserLIst/FavoritedBy/FavoritedByViewController.swift +++ b/Mastodon/Scene/Profile/UserLIst/FavoritedBy/FavoritedByViewController.swift @@ -47,7 +47,7 @@ extension FavoritedByViewController { } #endif - title = "Favorited By" + title = L10n.Scene.FavoritedBy.title view.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemBackgroundColor ThemeService.shared.currentTheme diff --git a/Mastodon/Scene/Profile/UserLIst/RebloggedBy/RebloggedByViewController.swift b/Mastodon/Scene/Profile/UserLIst/RebloggedBy/RebloggedByViewController.swift index ab208795..78988bb4 100644 --- a/Mastodon/Scene/Profile/UserLIst/RebloggedBy/RebloggedByViewController.swift +++ b/Mastodon/Scene/Profile/UserLIst/RebloggedBy/RebloggedByViewController.swift @@ -47,7 +47,7 @@ extension RebloggedByViewController { } #endif - title = "Favorited By" + title = L10n.Scene.RebloggedBy.title view.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemBackgroundColor ThemeService.shared.currentTheme diff --git a/MastodonSDK/Sources/MastodonLocalization/MastodonLocalization+Bundle.swift b/MastodonSDK/Sources/MastodonLocalization/MastodonLocalization+Bundle.swift new file mode 100644 index 00000000..3e5f62e4 --- /dev/null +++ b/MastodonSDK/Sources/MastodonLocalization/MastodonLocalization+Bundle.swift @@ -0,0 +1,14 @@ +// +// MastodonLocalization+Bundle.swift +// +// +// Created by MainasuK on 2022-5-17. +// + +import Foundation + +public enum MastodonLocalization { + public static var bundle: Bundle { + Bundle.module + } +} diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/FamiliarFollowersDashboardView+Configuration.swift b/MastodonSDK/Sources/MastodonUI/View/Content/FamiliarFollowersDashboardView+Configuration.swift index 78207023..0b63f848 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/FamiliarFollowersDashboardView+Configuration.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/FamiliarFollowersDashboardView+Configuration.swift @@ -12,7 +12,7 @@ extension FamiliarFollowersDashboardView { public func configure(familiarFollowers: Mastodon.Entity.FamiliarFollowers?) { assert(Thread.isMainThread) - let accounts = familiarFollowers?.accounts.prefix(4) ?? [] + let accounts = familiarFollowers?.accounts ?? [] viewModel.avatarURLs = accounts.map { $0.avatarImageURL() } viewModel.names = accounts.map { $0.displayNameWithFallback } diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/FamiliarFollowersDashboardView+ViewModel.swift b/MastodonSDK/Sources/MastodonUI/View/Content/FamiliarFollowersDashboardView+ViewModel.swift index cee71a45..a9bb2c5f 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/FamiliarFollowersDashboardView+ViewModel.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/FamiliarFollowersDashboardView+ViewModel.swift @@ -10,6 +10,7 @@ import UIKit import Combine import CoreDataStack import MastodonMeta +import MastodonLocalization extension FamiliarFollowersDashboardView { public final class ViewModel: ObservableObject { @@ -32,6 +33,9 @@ extension FamiliarFollowersDashboardView.ViewModel { UIContentSizeCategory.publisher ) .sink { avatarURLs, backgroundColor, contentSizeCategory in + // only using first 4 items + let avatarURLs = avatarURLs.prefix(4) + view.avatarContainerView.subviews.forEach { $0.removeFromSuperview() } let initialOffset = min(12 * 1.5, UIFontMetrics(forTextStyle: .headline).scaledValue(for: 12)) // max 1.5x @@ -82,12 +86,12 @@ extension FamiliarFollowersDashboardView.ViewModel { switch names.count { case 1..<3: - return "Followed by \(firstTwoNames)" - case 3: - return "Followed by \(firstTwoNames), and another mutual" + return L10n.Scene.Familiarfollowers.followedByNames(firstTwoNames) default: + // Note: SwiftGen generates wrong formate argv for "%1$@" let remains = count - 2 - return "Followed by \(firstTwoNames), and \(remains) mutuals" + let format = MastodonLocalization.bundle.localizedString(forKey: "plural.count.followed_by_and_mutual", value: nil, table: "Localizable") + return String(format: format, locale: .current, arguments: [firstTwoNames, remains]) } }() let document = MastodonContent(content: content, emojis: emojis) diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift index 44f7bb9a..f3d9f6f8 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift @@ -666,12 +666,11 @@ extension StatusView.ViewModel { let meidaAccessibilityLabel = $mediaViewConfigurations .map { configurations -> String? in let count = configurations.count - // TODO: i18n - return count > 0 ? "\(count) media" : nil + return L10n.Plural.Count.media(count) } // TODO: Toolbar - + Publishers.CombineLatest3( authorAccessibilityLabel, contentAccessibilityLabel,