Skip to content

Commit 4dc19f0

Browse files
parkerakaran-misra
andauthored
Introduce preferredLocales API (#1315)
Co-authored-by: Karan Miśra <[email protected]>
1 parent a8217de commit 4dc19f0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Sources/FoundationEssentials/Locale/Locale.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,15 +554,24 @@ public struct Locale : Hashable, Equatable, Sendable {
554554
// MARK: -
555555
//
556556

557-
/// Returns a list of the user's preferred languages.
557+
/// Returns a list of the user's preferred languages, as specified in Language & Region settings, taking into account any per-app language overrides.
558558
///
559559
/// - note: `Bundle` is responsible for determining the language that your application will run in, based on the result of this API and combined with the languages your application supports.
560560
/// - seealso: `Bundle.preferredLocalizations(from:)`
561561
/// - seealso: `Bundle.preferredLocalizations(from:forPreferences:)`
562+
/// - seealso: `Locale.preferredLocales`
562563
public static var preferredLanguages: [String] {
563564
LocaleCache.cache.preferredLanguages(forCurrentUser: false)
564565
}
565566

567+
/// Returns a list of the user’s preferred locales, as specified in Language & Region settings, taking into account any per-app language overrides.
568+
@available(FoundationPreview 6.2, *)
569+
public static var preferredLocales: [Locale] {
570+
return self.preferredLanguages.compactMap {
571+
Locale(identifier: $0)
572+
}
573+
}
574+
566575
private static let languageCodeKey = "kCFLocaleLanguageCodeKey"
567576
private static let scriptCodeKey = "kCFLocaleScriptCodeKey"
568577
private static let countryCodeKey = "kCFLocaleCountryCodeKey"

0 commit comments

Comments
 (0)