多语言BUG修复

This commit is contained in:
zeng 2025-05-13 13:54:39 +08:00
parent b4b867b7d4
commit a94e3a8fd7
9 changed files with 117 additions and 42 deletions

View File

@ -29,8 +29,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// SPLoginManager.manager.requestVisitorLogin(completer: nil)
SPLoginManager.manager.updateUserInfo(completer: nil)
///
SPLocalizedManager.shared.updateLocalizedData(completer: nil)
///
registerAPNS()

View File

@ -17,29 +17,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
guard let windowScene = (scene as? UIWindowScene) else { return }
///
NotificationCenter.default.addObserver(self, selector: #selector(localizedDidChange), name: SPLocalizedManager.localizedDidChange, object: nil)
let tabBarController = SPTabBarController()
SPAPPTool.mainTabBarController = tabBarController
let hasOpenApp = UserDefaults.standard.object(forKey: kSPHasBeenOpenedAPPDefaultsKey) as? Bool
///
let guideVc = SPGuideViewController()
///
NotificationCenter.default.addObserver(self, selector: #selector(reachabilityDidChangeNotification), name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil)
window = UIWindow(windowScene: windowScene)
if hasOpenApp != true && guideVc.lanuchVC != nil {
SPAPPTool.isAppOpen = false
guideVc.openAppBlock = {
self.handleOpenApp()
}
window?.rootViewController = guideVc
} else {
SPAPPTool.isAppOpen = true
window?.rootViewController = tabBarController
}
window?.makeKeyAndVisible()
startApp()
//线
timer = Timer.scheduledTimer(timeInterval: 60 * 10, target: self, selector: #selector(handleOnLine), userInfo: nil, repeats: true)
}
@ -84,27 +70,84 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
extension SceneDelegate {
private func startApp() {
let localizedManager = SPLocalizedManager.shared
///
if localizedManager.localizedDataLocalizedKey != localizedManager.currentLocalizedKey, let lanuchVC = SPAPPTool.getLanuchViewController() {
window?.rootViewController = lanuchVC
window?.makeKeyAndVisible()
SPLocalizedManager.shared.updateLocalizedData { [weak self] finish in
guard let self = self else { return }
self.setRootVC()
}
} else {
SPLocalizedManager.shared.updateLocalizedData(completer: nil)
setRootVC()
}
}
///线
@objc private func handleOnLine() {
SPStatAPI.requestStatOnLine()
}
///app
@objc private func handleOpenApp() {
window?.rootViewController = SPAPPTool.mainTabBarController!
window?.makeKeyAndVisible()
private func setRootVC() {
let hasOpenApp = UserDefaults.standard.object(forKey: kSPHasBeenOpenedAPPDefaultsKey) as? Bool
///
let guideVc = SPGuideViewController()
handleOpenAppMessage(webpageURL: nil)
if hasOpenApp != true && guideVc.lanuchVC != nil {
SPAPPTool.isAppOpen = false
guideVc.openAppBlock = {
self.handleOpenApp()
}
window?.rootViewController = guideVc
window?.makeKeyAndVisible()
} else {
SPAPPTool.isAppOpen = true
setTabBarController()
}
}
///
@objc private func localizedDidChange() {
MJRefreshConfig.default.languageCode = SPLocalizedManager.shared.mjLocalizedKey
private func setTabBarController() {
let tabBarController = SPTabBarController()
SPAPPTool.mainTabBarController = tabBarController
window?.rootViewController = tabBarController
window?.makeKeyAndVisible()
}
///app
@objc private func handleOpenApp() {
setTabBarController()
handleOpenAppMessage(webpageURL: nil)
}
}
extension SceneDelegate {
///
@objc private func localizedDidChange() {
MJRefreshConfig.default.languageCode = SPLocalizedManager.shared.mjLocalizedKey
setTabBarController()
}
///
@objc private func reachabilityDidChangeNotification() {
let localizedData = SPLocalizedManager.shared.localizedData ?? [:]
if SPNetworkReachabilityManager.manager.isReachable == true && localizedData.isEmpty {
///
self.startApp()
}
}
}

View File

@ -55,7 +55,9 @@ class SPNetworkReachabilityManager {
if self.isReachable == false {
print("++++++有网")
self.isReachable = true
NotificationCenter.default.post(name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil)
DispatchQueue.main.async {
NotificationCenter.default.post(name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil)
}
} else {
self.isReachable = true
}
@ -64,7 +66,9 @@ class SPNetworkReachabilityManager {
if self.isReachable == true {
print("++++++无网")
self.isReachable = false
NotificationCenter.default.post(name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil)
DispatchQueue.main.async {
NotificationCenter.default.post(name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil)
}
} else {
self.isReachable = false
}

View File

@ -13,7 +13,7 @@ class SPShortModel: SPModel, SmartCodable {
var id: String?
var all_coins: String?
var buy_type: String?
var collect_total: String?
var collect_total: Int?
var sp_description: String?
var episode_total: Int?
var horizontally_img: String?

View File

@ -40,7 +40,7 @@ class SPPlayLockView: UIView {
let label = UILabel()
label.font = .fontRegular(ofSize: 18)
label.textColor = .colorFFFFFF()
label.text = "movia_video_lock_tip".localized
label.text = "movia_video_lock_tip_01".localized
return label
}()

View File

@ -109,7 +109,8 @@ class SPPlayerControlView: UIView {
///
private lazy var collectButton: UIButton = {
let button = createFeatureButton(title: "movia_save".localized, selectedTitle: "movia_added".localized, image: UIImage(named: "collect_icon_01"), selectedImage: UIImage(named: "collect_icon_01_selected"))
// let button = createFeatureButton(title: "movia_save".localized, selectedTitle: "movia_added".localized, image: UIImage(named: "collect_icon_01"), selectedImage: UIImage(named: "collect_icon_01_selected"))
let button = createFeatureButton(title: "0", image: UIImage(named: "collect_icon_01"), selectedImage: UIImage(named: "collect_icon_01_selected"))
button.addTarget(self, action: #selector(handleCollectButton), for: .touchUpInside)
return button
}()
@ -235,7 +236,18 @@ extension SPPlayerControlView {
let isCollect = !(self.shortModel?.is_collect ?? false)
SPVideoAPI.requestCollectShort(isCollect: isCollect, shortPlayId: shortPlayId, videoId: videoId) {
SPVideoAPI.requestCollectShort(isCollect: isCollect, shortPlayId: shortPlayId, videoId: videoId) { [weak self] in
guard let self = self else { return }
var count = self.shortModel?.collect_total ?? 0
if isCollect {
count += 1
} else {
count -= 1
}
if count < 0 {
count = 0
}
self.shortModel?.collect_total = count
}
}
@ -252,6 +264,7 @@ extension SPPlayerControlView {
private func updateCollectButtonState() {
self.collectButton.isSelected = self.shortModel?.is_collect ?? false
self.collectButton.setTitle("\(self.shortModel?.collect_total ?? 0)", for: .normal)
}
}

View File

@ -9,7 +9,7 @@ import UIKit
class SPOrderRecordsPageViewController: SPViewController {
private lazy var titles: [String] = ["movia_Coin_Record".localized, "VIP Record".localized]
private lazy var titles: [String] = ["movia_Coin_Record".localized, "movia_VIP_Record".localized]
private lazy var viewControllers: [UIViewController] = {
let vc1 = SPCoinOrderRecordViewController()
let vc2 = SPVIPOrderRecordViewController()

View File

@ -13,8 +13,8 @@ class SPConsumptionRecordsCell: SPTableViewCell {
didSet {
titleLabel.text = "movia_Purchase_Single_Episode".localized
timeLabel.text = model?.created_at
desLabel.text = "Ep.\(model?.episode ?? "") \(model?.name ?? "")"
let episode = String(format: "movia_text_episcode_ios".localized, "\(model?.episode ?? "0")") + "\(model?.name ?? "")"
desLabel.text = episode
coinLabel.text = "-\(model?.coins ?? 0) " + "movia_profile_Coins".localized
}
}

View File

@ -11,25 +11,41 @@ class SPLocalizedManager: NSObject {
static let shared = SPLocalizedManager()
private let LocalizedUserDefaultsKey = "SPLocalizedManager.LocalizedUserDefaultsKey"
private let LocalizedDataUserDefaultsKey = "SPLocalizedManager.LocalizedDataUserDefaultsKey"
private let LocalizedDataLocalizedKeyUserDefaultsKey = "SPLocalizedManager.LocalizedDataLocalizedKeyUserDefaultsKey"
///
var languageList: [SPLanguageModel]?
///
private lazy var localizedData: [String : String]? = UserDefaults.standard.object(forKey: LocalizedDataUserDefaultsKey) as? [String : String]
private(set) lazy var localizedData: [String : String]? = UserDefaults.standard.object(forKey: LocalizedDataUserDefaultsKey) as? [String : String]
{
didSet {
UserDefaults.standard.set(localizedData, forKey: LocalizedDataUserDefaultsKey)
UserDefaults.standard.synchronize()
}
}
///key
private(set) lazy var localizedDataLocalizedKey: String? = UserDefaults.standard.object(forKey: LocalizedDataLocalizedKeyUserDefaultsKey) as? String
{
didSet {
UserDefaults.standard.set(localizedDataLocalizedKey, forKey: LocalizedDataLocalizedKeyUserDefaultsKey)
UserDefaults.standard.synchronize()
}
}
//
var currentLocalizedKey: String {
get {
// return UserDefaults.standard.string(forKey: userDefaultsKey) ?? Locale.preferredLanguages.first ?? "en"
return UserDefaults.standard.string(forKey: LocalizedUserDefaultsKey) ?? "en"
var key = (UserDefaults.standard.string(forKey: LocalizedUserDefaultsKey) ?? Locale.preferredLanguages.first) ?? "en"
if key.contains("zh-Hans") {
key = "zh"
} else if key.contains("zh-Hant") {
key = "zh_hk"
} else {
let arr = key.components(separatedBy: "-")
key = arr.first ?? "en"
}
return key
}
set {
UserDefaults.standard.set(newValue, forKey: LocalizedUserDefaultsKey)
@ -89,6 +105,7 @@ extension SPLocalizedManager {
}
if let localizedData = model.translates {
self.localizedDataLocalizedKey = key
self.localizedData = localizedData
completer?(true)
} else {