LanguageCode
- iOS
- 16+
- macOS
- 13+
- tvOS
- 16+
- watchOS
- 9+
struct LanguageCode
struct LanguageCode
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 Components
Represents locale-related attributes. You can use Locale.Components
to create a Locale
with specific overrides.
struct Currency
enum HourCycle
enum IdentifierType
struct Language
enum LanguageDirection
struct MeasurementSystem
struct NumberingSystem
struct Region
struct Script
struct Subdivision
struct Variant
enum Weekday
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol CustomDebugStringConvertible
A type with a customized textual representation suitable for debugging purposes.
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 Escapable
protocol ExpressibleByExtendedGraphemeClusterLiteral : ExpressibleByUnicodeScalarLiteral
A type that can be initialized with a string literal containing a single extended grapheme cluster.
protocol ExpressibleByStringLiteral : ExpressibleByExtendedGraphemeClusterLiteral
A type that can be initialized with a string literal.
protocol ExpressibleByUnicodeScalarLiteral
A type that can be initialized with a string literal containing a single Unicode scalar value.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol Sendable
init(_ identifier: String)
Creates a LanguageCode
type
init(from decoder: any Decoder) throws
init(stringLiteral value: String)
static var ainu: Locale.LanguageCode { get }
static var albanian: Locale.LanguageCode { get }
static var amharic: Locale.LanguageCode { get }
static var apacheWestern: Locale.LanguageCode { get }
static var arabic: Locale.LanguageCode { get }
static var armenian: Locale.LanguageCode { get }
static var assamese: Locale.LanguageCode { get }
static var assyrian: Locale.LanguageCode { get }
static var azerbaijani: Locale.LanguageCode { get }
static var bangla: Locale.LanguageCode { get }
static var belarusian: Locale.LanguageCode { get }
static var bodo: Locale.LanguageCode { get }
static var bulgarian: Locale.LanguageCode { get }
static var burmese: Locale.LanguageCode { get }
static var cantonese: Locale.LanguageCode { get }
static var catalan: Locale.LanguageCode { get }
static var cherokee: Locale.LanguageCode { get }
static var chinese: Locale.LanguageCode { get }
static var croatian: Locale.LanguageCode { get }
static var czech: Locale.LanguageCode { get }
static var danish: Locale.LanguageCode { get }
static var dhivehi: Locale.LanguageCode { get }
static var dogri: Locale.LanguageCode { get }
static var dutch: Locale.LanguageCode { get }
static var dzongkha: Locale.LanguageCode { get }
static var english: Locale.LanguageCode { get }
static var estonian: Locale.LanguageCode { get }
static var faroese: Locale.LanguageCode { get }
static var finnish: Locale.LanguageCode { get }
static var french: Locale.LanguageCode { get }
static var fula: Locale.LanguageCode { get }
static var georgian: Locale.LanguageCode { get }
static var german: Locale.LanguageCode { get }
static var greek: Locale.LanguageCode { get }
static var gujarati: Locale.LanguageCode { get }
static var hawaiian: Locale.LanguageCode { get }
static var hebrew: Locale.LanguageCode { get }
static var hindi: Locale.LanguageCode { get }
static var hungarian: Locale.LanguageCode { get }
static var icelandic: Locale.LanguageCode { get }
static var igbo: Locale.LanguageCode { get }
static var indonesian: Locale.LanguageCode { get }
static var irish: Locale.LanguageCode { get }
static var italian: Locale.LanguageCode { get }
static var japanese: Locale.LanguageCode { get }
static var kannada: Locale.LanguageCode { get }
static var kashmiri: Locale.LanguageCode { get }
static var kazakh: Locale.LanguageCode { get }
static var khmer: Locale.LanguageCode { get }
static var konkani: Locale.LanguageCode { get }
static var korean: Locale.LanguageCode { get }
static var kurdish: Locale.LanguageCode { get }
static var kurdishSorani: Locale.LanguageCode { get }
static var kyrgyz: Locale.LanguageCode { get }
static var lao: Locale.LanguageCode { get }
static var latvian: Locale.LanguageCode { get }
static var lithuanian: Locale.LanguageCode { get }
static var macedonian: Locale.LanguageCode { get }
static var maithili: Locale.LanguageCode { get }
static var malay: Locale.LanguageCode { get }
static var malayalam: Locale.LanguageCode { get }
static var maltese: Locale.LanguageCode { get }
static var manipuri: Locale.LanguageCode { get }
static var marathi: Locale.LanguageCode { get }
static var mongolian: Locale.LanguageCode { get }
static let multiple: Locale.LanguageCode
The mul
code: represents the language of some content when there are more than one languages
static var māori: Locale.LanguageCode { get }
static var navajo: Locale.LanguageCode { get }
static var nepali: Locale.LanguageCode { get }
static var norwegian: Locale.LanguageCode { get }
static var norwegianBokmål: Locale.LanguageCode { get }
static var norwegianNynorsk: Locale.LanguageCode { get }
static var odia: Locale.LanguageCode { get }
static var pashto: Locale.LanguageCode { get }
static var persian: Locale.LanguageCode { get }
static var polish: Locale.LanguageCode { get }
static var portuguese: Locale.LanguageCode { get }
static var punjabi: Locale.LanguageCode { get }
static var rohingya: Locale.LanguageCode { get }
static var romanian: Locale.LanguageCode { get }
static var russian: Locale.LanguageCode { get }
static var samoan: Locale.LanguageCode { get }
static var sanskrit: Locale.LanguageCode { get }
static var santali: Locale.LanguageCode { get }
static var serbian: Locale.LanguageCode { get }
static var sindhi: Locale.LanguageCode { get }
static var sinhala: Locale.LanguageCode { get }
static var slovak: Locale.LanguageCode { get }
static var slovenian: Locale.LanguageCode { get }
static var spanish: Locale.LanguageCode { get }
static var swahili: Locale.LanguageCode { get }
static var swedish: Locale.LanguageCode { get }
static var tagalog: Locale.LanguageCode { get }
static var tajik: Locale.LanguageCode { get }
static var tamil: Locale.LanguageCode { get }
static var telugu: Locale.LanguageCode { get }
static var thai: Locale.LanguageCode { get }
static var tibetan: Locale.LanguageCode { get }
static var tongan: Locale.LanguageCode { get }
static var turkish: Locale.LanguageCode { get }
static var turkmen: Locale.LanguageCode { get }
static var ukrainian: Locale.LanguageCode { get }
static let unavailable: Locale.LanguageCode
The zxx
code: used in cases when the content is not in any particular languages, such as images, symbols, etc.
static let uncoded: Locale.LanguageCode
The mis
code: represents languages that have not been included in the ISO standard yet
static let unidentified: Locale.LanguageCode
The und
code: used in cases where the language has not been identified
static var urdu: Locale.LanguageCode { get }
static var uyghur: Locale.LanguageCode { get }
static var uzbek: Locale.LanguageCode { get }
static var vietnamese: Locale.LanguageCode { get }
static var welsh: Locale.LanguageCode { get }
static var yiddish: Locale.LanguageCode { get }
var debugDescription: String { get }
var identifier: String { get set }
A two-letter or three-letter code supported by ISO 639, or a language code of your choice if using a custom language.
static func == (lhs: Locale.LanguageCode, rhs: Locale.LanguageCode) -> Bool
func encode(to encoder: any Encoder) throws
func hash(into hasher: inout Hasher)
enum IdentifierType
Types of ISO 639 language code.
init(extendedGraphemeClusterLiteral value: Self.StringLiteralType)
init(unicodeScalarLiteral value: Self.ExtendedGraphemeClusterLiteralType)
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.
import FoundationInternationalization
static var isoLanguageCodes: [Locale.LanguageCode] { get }
Returns a list of Locale
language codes that are two-letter language codes defined in ISO 639 and two-letter codes without a two-letter equivalent
var isISOLanguage: Bool { get }
Returns if the language is an ISO-639 language
func identifier(_ type: Locale.LanguageCode.IdentifierType) -> String?
Returns the ISO code of the given identifier type. Returns nil if the language isn’t a valid ISO language, or if the specified identifier type isn’t available to the language.