Components
Represents locale-related attributes. You can use Locale.Components
to create a Locale
with specific overrides.
- iOS
- 16+
- macOS
- 13+
- tvOS
- 16+
- watchOS
- 9+
struct Components
Represents locale-related attributes. You can use Locale.Components
to create a Locale
with specific overrides.
struct Components
import FoundationEssentials
struct Locale
Locale
encapsulates information about linguistic, cultural, and technological conventions and standards. Examples of information encapsulated by a locale include the symbol used for the decimal separator in numbers and the way dates are formatted.
init(components: Locale.Components)
Creates a Locale
with the specified locale components
init(from decoder: any Decoder) throws
init(identifier: String)
Return a locale with the specified identifier.
init(identifier: String, preferences: LocalePreferences?)
init(languageCode: Locale.LanguageCode? = nil, script: Locale.Script? = nil, languageRegion: Locale.Region? = nil)
init(languageComponents: Locale.Language.Components)
Creates a Locale
with the specified language components
static var autoupdatingCurrent: Locale { get }
Returns a locale which tracks the user’s current preferences.
static var current: Locale { get }
Returns the user’s current locale.
static var preferredLanguages: [String] { get }
Returns a list of the user’s preferred languages.
static func canonicalIdentifier(from string: String) -> String
Returns a canonical identifier from the given string.
static func canonicalLanguageIdentifier(from string: String) -> String
Returns a canonical language identifier from the given string.
static func identifier(fromComponents components: [String : String]) -> String
Constructs an identifier from a dictionary of components.
static func identifierDoesNotRequireSpecialCaseHandling(_ identifier: String) -> Bool
var alternateQuotationBeginDelimiter: String? { get }
Returns the alternate quotation begin delimiter of the locale.
var alternateQuotationEndDelimiter: String? { get }
Returns the alternate quotation end delimiter of the locale.
var availableNumberingSystems: [Locale.NumberingSystem] { get }
Returns all the valid numbering systems for the locale. For example, "ar-AE (Arabic (United Arab Emirates)"
has both "latn" (Latin digits)
and "arab" (Arabic-Indic digits)
numbering system.
var calendar: Calendar { get }
Returns the calendar for the locale, or the Gregorian calendar as a fallback.
var collation: Locale.Collation { get }
Returns the default collation used by the locale. Default is .standard
.
var collationIdentifier: String? { get }
Returns the collation identifier for the locale, or nil if it has none.
var collatorIdentifier: String? { get }
Returns the collator identifier of the locale.
var currency: Locale.Currency? { get }
Returns the currency of the locale. Returns nil if the data isn’t available.
var currencyCode: String? { get }
Returns the currency code of the locale.
var currencySymbol: String? { get }
Returns the currency symbol of the locale.
var customMirror: Mirror { get }
var debugDescription: String { get }
var decimalSeparator: String? { get }
Returns the decimal separator of the locale.
var description: String { get }
var firstDayOfWeek: Locale.Weekday { get }
Returns the first day of the week of the locale. Returns .sunday
as the default value if the data isn’t available to the requested locale.
var forceHourCycle: Locale.HourCycle? { get }
var forceMeasurementSystem: Locale.MeasurementSystem? { get }
var forceTemperatureUnit: LocalePreferences.TemperatureUnit? { get }
var groupingSeparator: String? { get }
Returns the grouping separator of the locale.
var hourCycle: Locale.HourCycle { get }
Returns the hour cycle such as whether it uses 12-hour clock or 24-hour clock. Default is .zeroToTwentyThree
if the data isn’t available. Calling this on .current
or .autoupdatingCurrent
returns user’s preference values as set in the system settings if available, overriding the default value of the user’s locale.
var identifier: String { get }
Returns the identifier of the locale.
var identifierCapturingPreferences: String { get }
var language: Locale.Language { get }
var languageCode: String? { get }
Returns the language code of the locale, or nil if has none.
var measurementSystem: Locale.MeasurementSystem { get }
var numberingSystem: Locale.NumberingSystem { get }
Returns the numbering system of the locale. If the locale has an explicitly specified numbering system in the identifier (e.g. bn_BD@numbers=latn
) or in the associated Locale.Components
, that numbering system is returned. Otherwise, returns the default numbering system of the locale. Returns "latn"
as the default value if the data isn’t available.
var prefs: LocalePreferences? { get }
var quotationBeginDelimiter: String? { get }
Returns the quotation begin delimiter of the locale.
var quotationEndDelimiter: String? { get }
Returns the quotation end delimiter of the locale.
var region: Locale.Region? { get }
Returns the region of the locale. For example, “US” for “en_US”, “GB” for “en_GB”, “PT” for “pt_PT”.
var regionCode: String? { get }
Returns the region code of the locale, or nil if it has none.
var scriptCode: String? { get }
Returns the script code of the locale, or nil if has none.
var subdivision: Locale.Subdivision? { get }
Returns the regional subdivision for the locale, or nil if there is none.
var temperatureUnit: LocalePreferences.TemperatureUnit { get }
var timeZone: TimeZone? { get }
var usesMetricSystem: Bool { get }
Returns true if the locale uses the metric system.
var variant: Locale.Variant? { get }
Returns the variant for the locale, or nil if it has none. For example, for the locale “en_POSIX”, returns “POSIX”.
var variantCode: String? { get }
Returns the variant code for the locale, or nil if it has none.
static func == (lhs: Locale, rhs: Locale) -> Bool
func encode(to encoder: any Encoder) throws
func forceFirstWeekday(_ calendar: Calendar.Identifier) -> Locale.Weekday?
func forceMinDaysInFirstWeek(_ calendar: Calendar.Identifier) -> Int?
func hash(into hasher: inout Hasher)
func identifier(_ type: Locale.IdentifierType) -> String
func localizedString(for calendarIdentifier: Calendar.Identifier) -> String?
Returns a localized string for a specified Calendar.Identifier
.
func localizedString(forCollationIdentifier collationIdentifier: String) -> String?
Returns a localized string for a specified ICU collation identifier.
func localizedString(forCollatorIdentifier collatorIdentifier: String) -> String?
Returns a localized string for a specified ICU collator identifier.
func localizedString(forCurrencyCode currencyCode: String) -> String?
Returns a localized string for a specified ISO 4217 currency code.
func localizedString(forIdentifier identifier: String) -> String?
Returns a localized string for a specified identifier.
func localizedString(forLanguageCode languageCode: String) -> String?
Returns a localized string for a specified language code.
func localizedString(forRegionCode regionCode: String) -> String?
Returns a localized string for a specified region code.
func localizedString(forScriptCode scriptCode: String) -> String?
Returns a localized string for a specified script code.
func localizedString(forVariantCode variantCode: String) -> String?
Returns a localized string for a specified variant code.
struct Collation
struct Currency
enum HourCycle
enum IdentifierType
struct Language
struct LanguageCode
enum LanguageDirection
struct MeasurementSystem
struct NumberingSystem
struct Region
struct Script
struct Subdivision
struct Variant
enum Weekday
protocol Decodable
A type that can decode itself from an external representation.
protocol Encodable
A type that can encode itself to an external representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol Sendable
init(from decoder: any Decoder) throws
init(languageCode: Locale.LanguageCode? = nil, script: Locale.Script? = nil, languageRegion: Locale.Region? = nil)
Creates a Locale.Components
with the specified language code, script and region for the language
var calendar: Calendar.Identifier?
Set this to override the default calendar. To request the default calendar used by the locale, use Locale.calendar
var collation: Locale.Collation?
Set this to override the string sort order. To request the default calendar used by the locale, use Locale.calendar
var currency: Locale.Currency?
Set this to override the currency. To request the default currency used by the locale, use Locale.currency
var firstDayOfWeek: Locale.Weekday?
Set this to override the first day of the week. To request the default first day of the week preferred by the locale, use Locale.firstDayOfWeek
var hourCycle: Locale.HourCycle?
Set this to override the hour cycle. To request the default hour cycle, use Locale.hourCycle
var languageComponents: Locale.Language.Components
Represents the language identifier a locale
var measurementSystem: Locale.MeasurementSystem?
Set this to override the measurement system. To request the default measurement system, use Locale.measurementSystem
var numberingSystem: Locale.NumberingSystem?
Set this to override the numbering system. To request the default numbering system used by the locale, use Locale.numberingSystem
var region: Locale.Region?
Set this to override the region for region-related preferences, such as measuring system, calendar, and first day of the week. If unset, the region of the language component is used
var subdivision: Locale.Subdivision?
Set this to override the regional subdivision of region
var timeZone: TimeZone?
Set this to specify a time zone to associate with this locale
var variant: Locale.Variant?
Set this to specify a variant used for the locale
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.
import FoundationInternationalization
init(identifier: String)
init(locale: Locale)
Creates a Locale.Components
with the identifier of the specified locale
.