diff --git a/Easydict/Swift/Feature/Localization/I18nHelper.swift b/Easydict/Swift/Feature/Localization/I18nHelper.swift index 957bd7790..0b33e73b5 100644 --- a/Easydict/Swift/Feature/Localization/I18nHelper.swift +++ b/Easydict/Swift/Feature/Localization/I18nHelper.swift @@ -25,12 +25,23 @@ class I18nHelper: NSObject { } var localizeCode: String { - UserDefaults.standard.string(forKey: languagePreferenceLocalKey) ?? LanguageState.LanguageType - .simplifiedChinese.rawValue + if let code = UserDefaults.standard.string(forKey: languagePreferenceLocalKey) { + return code + } + + if let localLanguageType = LanguageState.LanguageType(rawValue: Locale.current.identifier) { + return localLanguageType.rawValue + } + + if Locale.current.identifier == "zh_CN" { + return LanguageState.LanguageType.simplifiedChinese.rawValue + } + + return LanguageState.LanguageType.english.rawValue } var languageType: LanguageState.LanguageType { - LanguageState.LanguageType(rawValue: localizeCode) ?? .simplifiedChinese + LanguageState.LanguageType(rawValue: localizeCode) ?? .english } var isSimplifiedChineseLocalize: Bool { diff --git a/Easydict/Swift/Feature/Localization/LanguageState.swift b/Easydict/Swift/Feature/Localization/LanguageState.swift index b780ec730..5ff231133 100644 --- a/Easydict/Swift/Feature/Localization/LanguageState.swift +++ b/Easydict/Swift/Feature/Localization/LanguageState.swift @@ -32,7 +32,7 @@ class LanguageState: ObservableObject { } @AppStorage(languagePreferenceLocalKey) var language: LanguageType = (.init( - rawValue: Locale.current.identifier + rawValue: I18nHelper.shared.localizeCode ) ?? .simplifiedChinese) { didSet { NotificationCenter.default.post(name: .languagePreferenceChanged, object: nil)