Skip to content

Commit

Permalink
Update NSLocale+AppLanguage.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
linjie-firework committed May 9, 2024
1 parent 47c6180 commit 280165a
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ extension NSLocale {
cls: self,
originalSelector: #selector(getter: NSLocale.current),
customSelector: #selector(NSLocale.fw_current))
Swizzle.swizzleClassSelector(
cls: self,
originalSelector: #selector(getter: NSLocale.autoupdatingCurrent),
customSelector: #selector(NSLocale.fw_autoupdatingCurrent))
Swizzle.swizzleClassSelector(
cls: self,
originalSelector: #selector(getter: NSLocale.preferredLanguages),
customSelector: #selector(NSLocale.fw_preferredLanguages))
}

@objc static func fw_current() -> Locale {
Expand All @@ -21,4 +29,21 @@ extension NSLocale {

return fw_current()
}

@objc static func fw_autoupdatingCurrent() -> Locale {
if let language = AppLanguageManager.shared.appLanguage {
return Locale(identifier: language)
}

return fw_autoupdatingCurrent()
}

@objc static func fw_preferredLanguages() -> [String] {
let languages = fw_preferredLanguages()
if let language = AppLanguageManager.shared.appLanguage {
return [language] + languages
}

return languages
}
}

0 comments on commit 280165a

Please sign in to comment.