From e5935c8f77065789c126f336da710d1e19556577 Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Mon, 30 Oct 2023 11:46:30 +0300 Subject: [PATCH] Updated locale extensinon. --- .../Foundation/Extensions/LocaleExtension.swift | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Sources/SwiftBoost/Foundation/Extensions/LocaleExtension.swift b/Sources/SwiftBoost/Foundation/Extensions/LocaleExtension.swift index 0c21e96..9f3bab9 100644 --- a/Sources/SwiftBoost/Foundation/Extensions/LocaleExtension.swift +++ b/Sources/SwiftBoost/Foundation/Extensions/LocaleExtension.swift @@ -12,17 +12,8 @@ public extension Locale { } func localised(in locale: Locale) -> String? { - /** - Returns the identifier for the language code of the given `Locale`. - - 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`. - - - Parameter locale: The `Locale` for which the language code identifier is required. - - - 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. - */ + func supportedLangCodeId(for locale: Locale) -> String? { - // Checks for the availability of specific APIs introduced in iOS 16.0 and macOS 13.0 versions or later. if #available(iOS 16.0, macOS 13.0, *) { return locale.language.languageCode?.identifier } else { @@ -33,9 +24,11 @@ public extension Locale { guard let currentLanguageCode = { supportedLangCodeId(for: self) }() else { return nil } + guard let toLanguageCode = { supportedLangCodeId(for: locale) }() else { return nil } + let nslocale = NSLocale(localeIdentifier: toLanguageCode) let text = nslocale.displayName(forKey: NSLocale.Key.identifier, value: currentLanguageCode) return text?.localizedCapitalized