Skip to content

Commit

Permalink
Added language ID to locale.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvorobei committed Oct 30, 2023
1 parent e5935c8 commit 84365da
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions Sources/SwiftBoost/Foundation/Extensions/LocaleExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,17 @@ public extension Locale {
return dateString.contains(dateFormatter.amSymbol) || dateString.contains(dateFormatter.pmSymbol)
}

func localised(in locale: Locale) -> String? {

func supportedLangCodeId(for locale: Locale) -> String? {
if #available(iOS 16.0, macOS 13.0, *) {
return locale.language.languageCode?.identifier
} else {
return locale.languageCode
}
var languageID: String? {
if #available(iOS 16.0, macOS 13.0, *) {
return self.language.languageCode?.identifier
} else {
return self.languageCode
}

guard let currentLanguageCode = {
supportedLangCodeId(for: self)
}() else { return nil }

guard let toLanguageCode = {
supportedLangCodeId(for: locale)
}() else { return nil }

}

func localised(in locale: Locale) -> String? {
guard let currentLanguageCode = self.languageID else { return nil }
guard let toLanguageCode = locale.languageID else { return nil }
let nslocale = NSLocale(localeIdentifier: toLanguageCode)
let text = nslocale.displayName(forKey: NSLocale.Key.identifier, value: currentLanguageCode)
return text?.localizedCapitalized
Expand Down

0 comments on commit 84365da

Please sign in to comment.