Derived from | |
Framework | CoreFoundation/CoreFoundation.h |
Declared in | CFLocale.h |
Companion guides |
Unicode operations such as collation and text boundary determination can be affected by the conventions of a particular language or region. CFLocale objects specify language-specific or region-specific information for locale-sensitive operations.
The CFLocale opaque type provides support for obtaining available locales, obtaining localized locale names, and converting among locale data formats. Locale identifiers in Mac OS X follow the IETF’s BCP 47. CFLocale never uses Script Manager codes (except for the legacy support provided by CFLocaleCreateCanonicalLocaleIdentifierFromScriptManagerCodes
)—the Script Manager and all its concepts are deprecated.
For more information on locale identifiers and the use of CFLocale, see Locales Programming Guide. It is also useful to read the ICU’s User Guide for the Locale Class.
CFLocale is “toll-free bridged” with its Cocoa Foundation counterpart, NSLocale. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. Therefore, in a method where you see an NSLocale *
parameter, you can pass in a CFLocaleRef
, and in a function where you see a CFLocaleRef
parameter, you can pass in an NSLocale
instance. See Interchangeable Data Types for more information on toll-free bridging.
CFLocaleCopyISOCountryCodes
CFLocaleCopyISOLanguageCodes
CFLocaleCopyISOCurrencyCodes
CFLocaleCopyCommonISOCurrencyCodes
CFLocaleCreateCanonicalLocaleIdentifierFromScriptManagerCodes
CFLocaleCreateCanonicalLanguageIdentifierFromString
CFLocaleCreateCanonicalLocaleIdentifierFromString
CFLocaleCreateComponentsFromLocaleIdentifier
CFLocaleCreateLocaleIdentifierFromComponents
Returns an array of CFString objects that represents all locales for which locale data is available.
CFArrayRef CFLocaleCopyAvailableLocaleIdentifiers ( void );
An array of CFString objects that represents all locales for which locale data is available. Ownership follows the Create Rule.
CFLocale.h
Returns an array of strings that represents ISO currency codes for currencies in common use.
CFArrayRef CFLocaleCopyCommonISOCurrencyCodes ( void );
An array of CFString objects that represents ISO currency codes for currencies in common use. Ownership follows the Create Rule.
CFLocale.h
Returns a copy of the logical locale for the current user.
CFLocaleRef CFLocaleCopyCurrent ( void );
The logical locale for the current user that is formed from the settings for the current user’s chosen system locale overlaid with any custom settings the user has specified in System Preferences. May return a retained cached object, not a new object. Ownership follows the Create Rule.
Settings you get from this locale do not change as a user's preferences are changed so that your operations are consistent. Typically you perform some operations on the returned object and then release it. Since the returned object may be cached, you do not need to hold on to it indefinitely.
Note that locale settings are independent of the user’s language setting. The language of the current locale may not correspond to the language at the first index in the AppleLanguages
array from user defaults. For more details, see Locale Concepts in Locales Programming Guide; see also CFLocaleCopyPreferredLanguages
.
CFLocale.h
Returns the display name for the given value.
CFStringRef CFLocaleCopyDisplayNameForPropertyValue ( CFLocaleRef displayLocale, CFStringRef key, CFStringRef value );
A locale object.
A string that identifies the type that value is. It must be one of the standard locale property keys (see “Locale Property Keys”).
The value for which the display name is required.
The display name for value. Returns NULL
if there was a problem creating the object. Ownership follows the Create Rule.
Note that not all locale property keys have values with display name values.
CFLocale.h
Returns an array of CFString objects that represents all known legal ISO country codes.
CFArrayRef CFLocaleCopyISOCountryCodes ( void );
An array of CFString objects that represents all known legal ISO country codes. Ownership follows the Create Rule.
Note: many of these will not have any supporting locale data in Mac OS X.
CFLocale.h
Returns an array of CFString objects that represents all known legal ISO currency codes.
CFArrayRef CFLocaleCopyISOCurrencyCodes ( void );
An array of CFString objects that represents all known legal ISO currency codes.Ownership follows the Create Rule.
Note: many of these will not have any supporting locale data in Mac OS X.
CFLocale.h
Returns an array of CFString objects that represents all known legal ISO language codes.
CFArrayRef CFLocaleCopyISOLanguageCodes ( void );
An array of CFString objects that represents all known legal ISO language codes. Ownership follows the Create Rule.
Note: many of these will not have any supporting locale data in Mac OS X.
CFLocale.h
Returns the array of canonicalized locale IDs that the user prefers.
CFArrayRef CFLocaleCopyPreferredLanguages ( void );
The array of canonicalized CFString locale IDs that the current user prefers. Ownership follows the Create Rule.
CFLocale.h
Creates a locale for the given arbitrary locale identifier.
CFLocaleRef CFLocaleCreate ( CFAllocatorRef allocator, CFStringRef localeIdentifier );
The allocator to use to allocate memory for the new object. Pass NULL
or kCFAllocatorDefault
to use the current default allocator.
A string representation of an arbitrary locale identifier.
A new locale that corresponds to the arbitrary locale identifier localeIdentifier. Returns NULL
if there was a problem creating the object. Ownership follows the Create Rule.
CFLocale.h
Returns a canonical language identifier by mapping an arbitrary locale identification string to the canonical identifier
CFStringRef CFLocaleCreateCanonicalLanguageIdentifierFromString ( CFAllocatorRef allocator, CFStringRef localeIdentifier );
The allocator to use to allocate memory for the new object. Pass NULL
or kCFAllocatorDefault
to use the current default allocator.
A string representation of an arbitrary locale identifier.
A string that represents the canonical language identifier for the specified arbitrary locale identifier. Returns NULL
if there was a problem creating the object. Ownership follows the Create Rule.
CFLocale.h
Returns a canonical locale identifier from given language and region codes.
CFStringRef CFLocaleCreateCanonicalLocaleIdentifierFromScriptManagerCodes ( CFAllocatorRef allocator, LangCode lcode, RegionCode rcode );
The allocator to use to allocate memory for the new object. Pass NULL
or kCFAllocatorDefault
to use the current default allocator.
A Mac OS X language code.
A Mac OS X region code.
A canonical locale identifier created by mapping lcode and rcode to a locale. Returns NULL
if there was a problem creating the object. Ownership follows the Create Rule.
CFLocale.h
Returns a canonical locale identifier by mapping an arbitrary locale identification string to the canonical identifier.
CFStringRef CFLocaleCreateCanonicalLocaleIdentifierFromString ( CFAllocatorRef allocator, CFStringRef localeIdentifier );
The allocator to use to allocate memory for the new object. Pass NULL
or kCFAllocatorDefault
to use the current default allocator.
A string representation of an arbitrary locale identifier (for example, “English”).
A canonical locale identifier created by mapping the arbitrary locale identification string to the canonical identifier for the corresponding locale (for example, “en”). Returns NULL
if there was a problem creating the object. Ownership follows the Create Rule.
CFLocale.h
Returns a dictionary containing the result from parsing a locale ID consisting of language, script, country, variant, and keyword/value pairs.
CFDictionaryRef CFLocaleCreateComponentsFromLocaleIdentifier ( CFAllocatorRef allocator, CFStringRef localeID );
The allocator to use to allocate memory for the new object. Pass NULL
or kCFAllocatorDefault
to use the current default allocator.
The locale ID to be used when creating the locale dictionary.
A dictionary containing the result from parsing a locale ID consisting of language, script, country, variant, and keyword/value pairs. Returns NULL
if there was a problem creating the object. Ownership follows the Create Rule.
The dictionary keys are the constant CFString objects that correspond to the locale ID components; the values correspond to constants where available. For example: the string "en_US@calendar=japanese" yields a dictionary with three entries: kCFLocaleLanguageCode
=en
, kCFLocaleCountryCode
=US
, and kCFLocaleCalendarIdentifier
=
kCFJapaneseCalendar
. See also CFLocaleCreateLocaleIdentifierFromComponents
.
CFLocale.h
Returns a copy of a locale.
CFLocaleRef CFLocaleCreateCopy ( CFAllocatorRef allocator, CFLocaleRef locale );
The allocator to use to allocate memory for the new object. Pass NULL
or kCFAllocatorDefault
to use the current default allocator.
The locale object to copy.
A new locale that is a copy of locale. Returns NULL
if there was a problem creating the object. Ownership follows the Create Rule.
CFLocale.h
Returns a locale identifier consisting of language, script, country, variant, and keyword/value pairs derived from a dictionary containing the source information.
CFStringRef CFLocaleCreateLocaleIdentifierFromComponents ( CFAllocatorRef allocator, CFDictionaryRef dictionary );
The allocator to use to allocate memory for the new object. Pass NULL
or kCFAllocatorDefault
to use the current default allocator.
The dictionary to use when creating the locale identifier.
A locale identifier consisting of language, script, country, variant, and keyword/value pairs derived from dictionary. Returns NULL
if there was a problem creating the string. Ownership follows the Create Rule.
Reverses the actions of CFLocaleCreateComponentsFromLocaleIdentifier
, creating a single string from the data in the specified dictionary. For example, the dictionary {kCFLocaleLanguageCode
=en
,
kCFLocaleCountryCode
=US
,
kCFLocaleCalendarIdentifier
=
kCFJapaneseCalendar
}
becomes "en_US@calendar=japanese"
.
CFLocale.h
Returns the given locale's identifier.
CFStringRef CFLocaleGetIdentifier ( CFLocaleRef locale );
The locale object to examine.
A string representation of locale’s identifier. This may not be the same string that was used to create the locale—it may be canonicalized. Ownership follows the Get Rule.
CFLocale.h
Returns the root, canonical locale.
CFLocaleRef CFLocaleGetSystem ( void );
The root, canonical locale. Ownership follows the Get Rule.
The root locale contains fixed backstop settings for all locale information.
CFLocale.h
Returns the type identifier for the CFLocale opaque type.
CFTypeID CFLocaleGetTypeID ( void );
The type identifier for the CFLocale opaque type.
CFLocale.h
Returns the corresponding value for the given key of a locale’s key-value pair.
CFTypeRef CFLocaleGetValue ( CFLocaleRef locale, CFStringRef key );
The locale object to examine.
The key for which to obtain the corresponding value. Possible values are described in “Locale Property Keys.”
The value corresponding to the given key in locale. The value may be any type of CFType object. Ownership follows the Get Rule.
Locale objects use key-value pairs to store property values. Use this function to get the value of a specific property.
CFLocale.h
A reference to a CFLocale object.
typedef const struct __CFLocale *CFLocaleRef;
CFLocale.h
Predefined locale keys used to get property values.
const CFStringRef kCFLocaleMeasurementSystem; const CFStringRef kCFLocaleDecimalSeparator; const CFStringRef kCFLocaleGroupingSeparator; const CFStringRef kCFLocaleCurrencySymbol; const CFStringRef kCFLocaleCurrencyCode; const CFStringRef kCFLocaleIdentifier; const CFStringRef kCFLocaleLanguageCode; const CFStringRef kCFLocaleCountryCode; const CFStringRef kCFLocaleScriptCode; const CFStringRef kCFLocaleVariantCode; const CFStringRef kCFLocaleExemplarCharacterSet; const CFStringRef kCFLocaleCalendarIdentifier; const CFStringRef kCFLocaleCalendar; const CFStringRef kCFLocaleCollationIdentifier; const CFStringRef kCFLocaleUsesMetricSystem;
kCFLocaleMeasurementSystem
Specifies the measurement system used.
The corresponding value is a CFString, for example “Metric” or “U.S.”.
Available in Mac OS X v10.3 and later.
Declared in CFLocale.h
.
kCFLocaleDecimalSeparator
Specifies the decimal point string.
The corresponding value is a CFString, for example “.” or “,”.
Available in Mac OS X v10.3 and later.
Declared in CFLocale.h
.
kCFLocaleGroupingSeparator
Specifies the separator string between groups of digits.
The corresponding value is a CFString, for example “,” or “.”.
Available in Mac OS X v10.3 and later.
Declared in CFLocale.h
.
kCFLocaleCurrencySymbol
Specifies the currency symbol.
The corresponding value is a CFString, for example “$” or “£”.
Available in Mac OS X v10.3 and later.
Declared in CFLocale.h
.
kCFLocaleCurrencyCode
Specifies the locale currency code.
The corresponding value is a CFString, for example “USD” or “GBP”.
Available in Mac OS X v10.3 and later.
Declared in CFLocale.h
.
kCFLocaleIdentifier
Specifies locale identifier.
The corresponding value is a CFString containing the POSIX locale identifier as used by ICU, such as “ja_JP
”. If you have a variant locale or a different currency or calendar, it can be as complex as “en_US_POSIX@calendar=japanese;currency=EUR
” or “az_Cyrl_AZ@calendar=buddhist;currency=JPY
”.
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
kCFLocaleLanguageCode
Specifies the locale language code.
The corresponding value is a CFString containing an ISO 639-x/IETF BCP 47 language identifier, such as “ja
”.
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
kCFLocaleCountryCode
Specifies the locale country code.
The corresponding value is a CFString containing an ISO county code, such as “JP
”.
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
kCFLocaleScriptCode
Specifies the locale script code.
The corresponding value is a CFString containing a Unicode script tag (strictly, an ISO 15924 script tag). Usually this is empty (it is for “ja_JP
”). It may be present for locales where a script must be specified, for example “uz-Latn-UZ
” vs. “uz-Cyrl-UZ
” for Uzbek in Latin vs. Cyrillic (in the first case the script code is “Latn
”, and in the second it is “Cyrl
”).
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
kCFLocaleVariantCode
Specifies the locale variant code.
The corresponding value is a CFString containing the variant name. The variant code is arbitrary and application-specific. ICU adds “_EURO
” to its locale designations for locales that support the Euro currency. For “en_US_POSIX
” the variant is “POSIX
”, and for “hy_AM_REVISED
” it is “REVISED
”.
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
kCFLocaleExemplarCharacterSet
Specifies the locale character set.
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
kCFLocaleCalendarIdentifier
Specifies the locale calendar identifier.
The corresponding value is a CFString containing the calendar identifier (for possible values, see “Locale Calendar Identifiers”
).
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
kCFLocaleCalendar
Specifies the locale calendar.
The corresponding value is a CFCalendar.
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
kCFLocaleCollationIdentifier
Specifies the locale collation identifier.
The corresponding value is a collation.
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
kCFLocaleUsesMetricSystem
Specifies the whether the locale uses the metric system.
The corresponding value is a CFBoolean.
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
Locale objects use key-value pairs to store property values. Use the CFLocaleGetValue
function to get the value of a specific property listed above.
Predefined locale keys used to get calendar values—values for kCFLocaleCalendarIdentifier
.
const CFStringRef kCFGregorianCalendar; const CFStringRef kCFBuddhistCalendar; const CFStringRef kCFChineseCalendar; const CFStringRef kCFHebrewCalendar; const CFStringRef kCFIslamicCalendar; const CFStringRef kCFIslamicCivilCalendar; const CFStringRef kCFJapaneseCalendar;
kCFGregorianCalendar
Specifies the Gregorian calendar.
Available in Mac OS X v10.3 and later.
Declared in CFLocale.h
.
kCFBuddhistCalendar
Specifies the Buddhist calendar.
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
kCFChineseCalendar
Specifies the Chinese calendar.
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
kCFHebrewCalendar
Specifies the Hebrew calendar.
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
kCFIslamicCalendar
Specifies the Islamic calendar.
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
kCFIslamicCivilCalendar
Specifies the Islamic Civil calendar.
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
kCFJapaneseCalendar
Specifies the Japanese calendar.
Available in Mac OS X v10.4 and later.
Declared in CFLocale.h
.
Locale objects use key-value pairs to store property values. Use the CFLocaleGetValue
function to get the value of a specific property listed above.
Identifier for notification sent if the current locale changes.
const CFStringRef kCFLocaleCurrentLocaleDidChangeNotification
kCFLocaleCurrentLocaleDidChangeNotification
Identifier for the notification sent if the current locale changes.
This is a local notification posted when the user changes locale information in the System Preferences panel. Keep in mind that there is no order in how notifications are delivered to observers; frameworks or other parts of your code may also be observing this notification to take their own actions, and these may not have occurred at the time you receive the notification.
There is no object or user info for this notification.
Available in Mac OS X v10.5 and later.
Declared in CFLocale.h
.
CFLocale.h
© 2003, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-05-23)