From 2f98f6043a22aa9408bbb1309e6c561bbe38fdff Mon Sep 17 00:00:00 2001 From: choykarl <253440030@qq.com> Date: Sat, 23 Mar 2024 15:13:46 +0800 Subject: [PATCH] remove the EZ prefix in swift. --- Easydict.xcodeproj/project.pbxproj | 16 ++++++++-------- .../Swift/Notification/Notification+Name.swift | 4 ++++ Easydict/NewApp/EasydictApp.swift | 4 ++-- .../{EZI18nHelper.swift => I18nHelper.swift} | 7 ++++--- .../LanguagePreference/LanguageState.swift | 5 +---- ...calizedBundle.swift => LocalizedBundle.swift} | 5 +++-- .../Utility/Extensions/LanguageExtensions.swift | 2 +- 7 files changed, 23 insertions(+), 20 deletions(-) rename Easydict/NewApp/LanguagePreference/{EZI18nHelper.swift => I18nHelper.swift} (90%) rename Easydict/NewApp/LanguagePreference/{EZLocalizedBundle.swift => LocalizedBundle.swift} (63%) diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index 6a2f0ed94..b0a6ae21a 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -274,8 +274,8 @@ 62E2BF4C2B4082BA00E42D38 /* AliTranslateType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E2BF492B4082BA00E42D38 /* AliTranslateType.swift */; }; 62ED29A22B15F1F500901F51 /* EZWrapView.m in Sources */ = {isa = PBXBuildFile; fileRef = 62ED29A12B15F1F500901F51 /* EZWrapView.m */; }; 6A8C988E2BAC88B500DB835A /* LanguageState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A8C988C2BAC88B500DB835A /* LanguageState.swift */; }; - 6A8C988F2BAC88B500DB835A /* EZI18nHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A8C988D2BAC88B500DB835A /* EZI18nHelper.swift */; }; - 6A8C98952BAE841600DB835A /* EZLocalizedBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A8C98942BAE841600DB835A /* EZLocalizedBundle.swift */; }; + 6A8C988F2BAC88B500DB835A /* I18nHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A8C988D2BAC88B500DB835A /* I18nHelper.swift */; }; + 6A8C98952BAE841600DB835A /* LocalizedBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A8C98942BAE841600DB835A /* LocalizedBundle.swift */; }; 6ADED1552BAE8809004A15BE /* NSBundle+LanguagePreference.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ADED1542BAE8809004A15BE /* NSBundle+LanguagePreference.m */; }; 960835502B6791F200C6A931 /* Shortcut+Validator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9608354F2B6791F200C6A931 /* Shortcut+Validator.swift */; }; 96099AE22B5D40330055C4DD /* ShortcutTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96099AE12B5D40330055C4DD /* ShortcutTab.swift */; }; @@ -805,8 +805,8 @@ 62ED29A12B15F1F500901F51 /* EZWrapView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZWrapView.m; sourceTree = ""; }; 6372B33DFF803C7096A82250 /* Pods_Easydict.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Easydict.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6A8C988C2BAC88B500DB835A /* LanguageState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LanguageState.swift; sourceTree = ""; }; - 6A8C988D2BAC88B500DB835A /* EZI18nHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EZI18nHelper.swift; sourceTree = ""; }; - 6A8C98942BAE841600DB835A /* EZLocalizedBundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EZLocalizedBundle.swift; sourceTree = ""; }; + 6A8C988D2BAC88B500DB835A /* I18nHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = I18nHelper.swift; sourceTree = ""; }; + 6A8C98942BAE841600DB835A /* LocalizedBundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalizedBundle.swift; sourceTree = ""; }; 6ADED1542BAE8809004A15BE /* NSBundle+LanguagePreference.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSBundle+LanguagePreference.m"; sourceTree = ""; }; 91E3E579C6DB88658B4BB102 /* Pods-Easydict.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Easydict.release.xcconfig"; path = "Target Support Files/Pods-Easydict/Pods-Easydict.release.xcconfig"; sourceTree = ""; }; 9608354F2B6791F200C6A931 /* Shortcut+Validator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Shortcut+Validator.swift"; sourceTree = ""; }; @@ -2252,9 +2252,9 @@ 6A8C988B2BAC88A600DB835A /* LanguagePreference */ = { isa = PBXGroup; children = ( - 6A8C988D2BAC88B500DB835A /* EZI18nHelper.swift */, + 6A8C988D2BAC88B500DB835A /* I18nHelper.swift */, 6A8C988C2BAC88B500DB835A /* LanguageState.swift */, - 6A8C98942BAE841600DB835A /* EZLocalizedBundle.swift */, + 6A8C98942BAE841600DB835A /* LocalizedBundle.swift */, 6ADED1542BAE8809004A15BE /* NSBundle+LanguagePreference.m */, ); path = LanguagePreference; @@ -2948,7 +2948,7 @@ 03B0230229231FA6001C7E63 /* EZWordResultView.m in Sources */, 0399C6A529A747E600B4AFCC /* EZDeepLTranslateResponse.m in Sources */, 17BCAEF82B0DFF9000A7D372 /* EZNiuTransTranslate.m in Sources */, - 6A8C98952BAE841600DB835A /* EZLocalizedBundle.swift in Sources */, + 6A8C98952BAE841600DB835A /* LocalizedBundle.swift in Sources */, 039F5506294B6E29004AB940 /* EZSettingViewController.m in Sources */, 03BD281E29481C0400F5891A /* EZAudioPlayer.m in Sources */, 0A8685C82B552A590022534F /* DisabledAppTab.swift in Sources */, @@ -3030,7 +3030,7 @@ 03B0232829231FA6001C7E63 /* NSTextView+Height.m in Sources */, 03B0232129231FA6001C7E63 /* NSPasteboard+MM.m in Sources */, 03D043522928935300E7559E /* EZMainQueryWindow.m in Sources */, - 6A8C988F2BAC88B500DB835A /* EZI18nHelper.swift in Sources */, + 6A8C988F2BAC88B500DB835A /* I18nHelper.swift in Sources */, 03D8B26E292DBD2000D5A811 /* EZCoordinateUtils.m in Sources */, 03B0232029231FA6001C7E63 /* NSWindow+MM.m in Sources */, 0AC8A8432B6957B0006DA5CC /* BingService+ConfigurableService.swift in Sources */, diff --git a/Easydict/Feature/Utility/Swift/Notification/Notification+Name.swift b/Easydict/Feature/Utility/Swift/Notification/Notification+Name.swift index bae75eb23..7addc58c7 100644 --- a/Easydict/Feature/Utility/Swift/Notification/Notification+Name.swift +++ b/Easydict/Feature/Utility/Swift/Notification/Notification+Name.swift @@ -12,6 +12,8 @@ extension Notification.Name { static let serviceHasUpdated = Notification.Name(EZServiceHasUpdatedNotification) static let openSettings = Notification.Name(EZOpenSettingsNotification) + + static let languagePreferenceChanged = Notification.Name(I18nHelper.languagePreferenceChangedNotification) } @objc @@ -19,4 +21,6 @@ extension NSNotification { public static let serviceHasUpdated = Notification.Name.serviceHasUpdated public static let openSettings = Notification.Name.openSettings + + public static let languagePreferenceChanged = Notification.Name.languagePreferenceChanged } diff --git a/Easydict/NewApp/EasydictApp.swift b/Easydict/NewApp/EasydictApp.swift index a6ad3e1b7..5d77f14fe 100644 --- a/Easydict/NewApp/EasydictApp.swift +++ b/Easydict/NewApp/EasydictApp.swift @@ -35,7 +35,7 @@ struct EasydictApp: App { MenuBarExtra(isInserted: $hideMenuBar.toggledValue) { MenuItemView() .environmentObject(languageState) - .environment(\.locale, .init(identifier: EZI18nHelper.shared.localizeCode)) + .environment(\.locale, .init(identifier: I18nHelper.shared.localizeCode)) } label: { Label { Text("Easydict") @@ -66,7 +66,7 @@ struct EasydictApp: App { Settings { SettingView().environmentObject(languageState).environment( \.locale, - .init(identifier: EZI18nHelper.shared.localizeCode) + .init(identifier: I18nHelper.shared.localizeCode) ) } } diff --git a/Easydict/NewApp/LanguagePreference/EZI18nHelper.swift b/Easydict/NewApp/LanguagePreference/I18nHelper.swift similarity index 90% rename from Easydict/NewApp/LanguagePreference/EZI18nHelper.swift rename to Easydict/NewApp/LanguagePreference/I18nHelper.swift index 47a6c053e..e98a14297 100644 --- a/Easydict/NewApp/LanguagePreference/EZI18nHelper.swift +++ b/Easydict/NewApp/LanguagePreference/I18nHelper.swift @@ -8,12 +8,13 @@ import SwiftUI -// MARK: - EZI18nHelper +// MARK: - I18nHelper @objcMembers -class EZI18nHelper: NSObject { +@objc(EZI18nHelper) +class I18nHelper: NSObject { static let languagePreferenceChangedNotification = "EZLanguagePreferenceChangedNotification" - static let shared = EZI18nHelper() + static let shared = I18nHelper() var localizedBundle: Bundle { let res = localizeCode diff --git a/Easydict/NewApp/LanguagePreference/LanguageState.swift b/Easydict/NewApp/LanguagePreference/LanguageState.swift index 51732665e..2ebb4f3fc 100644 --- a/Easydict/NewApp/LanguagePreference/LanguageState.swift +++ b/Easydict/NewApp/LanguagePreference/LanguageState.swift @@ -35,10 +35,7 @@ class LanguageState: ObservableObject { rawValue: Locale.current.identifier ) ?? .simplifiedChinese) { didSet { - NotificationCenter.default.post( - name: NSNotification.Name(rawValue: EZI18nHelper.languagePreferenceChangedNotification), - object: nil - ) + NotificationCenter.default.post(name: .languagePreferenceChanged, object: nil) } } } diff --git a/Easydict/NewApp/LanguagePreference/EZLocalizedBundle.swift b/Easydict/NewApp/LanguagePreference/LocalizedBundle.swift similarity index 63% rename from Easydict/NewApp/LanguagePreference/EZLocalizedBundle.swift rename to Easydict/NewApp/LanguagePreference/LocalizedBundle.swift index 36426650d..e532e181c 100644 --- a/Easydict/NewApp/LanguagePreference/EZLocalizedBundle.swift +++ b/Easydict/NewApp/LanguagePreference/LocalizedBundle.swift @@ -8,8 +8,9 @@ import Foundation -class EZLocalizedBundle: Bundle { +@objc(EZLocalizedBundle) +class LocalizedBundle: Bundle { override func localizedString(forKey key: String, value: String?, table tableName: String?) -> String { - EZI18nHelper.shared.localizedBundle.localizedString(forKey: key, value: value, table: tableName) + I18nHelper.shared.localizedBundle.localizedString(forKey: key, value: value, table: tableName) } } diff --git a/Easydict/NewApp/Utility/Extensions/LanguageExtensions.swift b/Easydict/NewApp/Utility/Extensions/LanguageExtensions.swift index f28adea1c..1aae6f356 100644 --- a/Easydict/NewApp/Utility/Extensions/LanguageExtensions.swift +++ b/Easydict/NewApp/Utility/Extensions/LanguageExtensions.swift @@ -55,7 +55,7 @@ extension Language { } public var localizedName: String { - if EZI18nHelper.shared.isSimplifiedChineseLocalize { + if I18nHelper.shared.isSimplifiedChineseLocalize { chineseName } else { if self == .auto {