Returns the display name for the given locale component value.
SDKs
- iOS 2.0+
- macOS 10.4+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
Parameters
key
The locale property key of
value
. For possible values, seeNSLocale
..Key value
A value for
key
.
Return Value
The display name for value
.
Discussion
Not all locale property keys have values with display name values.
You can use the identifier
key to get the name of a locale in the language of another locale, as illustrated in the following examples.
let frLocale = NSLocale(localeIdentifier: "fr_FR")
print(frLocale.displayNameForKey(NSLocaleIdentifier, value: "fr_FR")!)
// "français (France)”
print(frLocale.displayNameForKey(NSLocaleIdentifier, value: "en_US")!)
// "anglais (États-Unis)”
The following example uses the en
locale.
let gbLocale = NSLocale(localeIdentifier: "en_GB")
print(gbLocale.displayNameForKey(NSLocaleIdentifier, value: "fr_FR")!)
// "French (France)”
print(gbLocale.displayNameForKey(NSLocaleIdentifier, value: "en_US")!)
// "English (United States)”