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 bb1f46c20..1e60f7a90 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 1b9efa1fb..decc1ee97 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 eb0872227..c125b0214 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 7316be5aa..0e2bc64ed 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 ab2087954..78988bb41 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 000000000..3e5f62e40 --- /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 782070232..0b63f848e 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 cee71a45f..a9bb2c5f0 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 44f7bb9ab..f3d9f6f80 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,