Skip to content

Commit e5935c8

Browse files
committed
Updated locale extensinon.
1 parent 5885499 commit e5935c8

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

Sources/SwiftBoost/Foundation/Extensions/LocaleExtension.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,8 @@ public extension Locale {
1212
}
1313

1414
func localised(in locale: Locale) -> String? {
15-
/**
16-
Returns the identifier for the language code of the given `Locale`.
17-
18-
This method checks for the availability of specific APIs introduced in iOS 16.0 and macOS 13.0 versions or later. If these APIs are available, it returns the `identifier` property of the `languageCode` from the `Locale`. Otherwise, it uses the `languageCode` property directly from the `Locale`.
19-
20-
- Parameter locale: The `Locale` for which the language code identifier is required.
21-
22-
- Returns: The language code identifier of the given `Locale`. If the specific APIs are unavailable (i.e., the device's OS version is older than iOS 16.0 or macOS 13.0), it returns the language code directly.
23-
*/
15+
2416
func supportedLangCodeId(for locale: Locale) -> String? {
25-
// Checks for the availability of specific APIs introduced in iOS 16.0 and macOS 13.0 versions or later.
2617
if #available(iOS 16.0, macOS 13.0, *) {
2718
return locale.language.languageCode?.identifier
2819
} else {
@@ -33,9 +24,11 @@ public extension Locale {
3324
guard let currentLanguageCode = {
3425
supportedLangCodeId(for: self)
3526
}() else { return nil }
27+
3628
guard let toLanguageCode = {
3729
supportedLangCodeId(for: locale)
3830
}() else { return nil }
31+
3932
let nslocale = NSLocale(localeIdentifier: toLanguageCode)
4033
let text = nslocale.displayName(forKey: NSLocale.Key.identifier, value: currentLanguageCode)
4134
return text?.localizedCapitalized

0 commit comments

Comments
 (0)