Instance Method

displayNameForKey:value:

Returns the display name for the given locale component value.

Declaration

- (NSString *)displayNameForKey:(NSLocaleKey)key value:(id)value;

Parameters

key

The locale property key of value. For possible values, see NSLocaleKey.

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 NSLocaleIdentifier key to get the name of a locale in the language of another locale, as illustrated in the following examples.

NSLocale *frLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"fr_FR"];
NSLog(@"%@", [frLocale displayNameForKey:NSLocaleIdentifier value:@"fr_FR"]);
// "français (France)”
NSLog(@"%@", [frLocale displayNameForKey:NSLocaleIdentifier value:@"en_US"]);
// "anglais (États-Unis)”

The following example uses the en_GB locale.

NSLocale *gbLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"];
NSLog(@"%@", [gbLocale displayNameForKey:NSLocaleIdentifier value:@"fr_FR"]);
// "French (France)”
NSLog(@"%@", [gbLocale displayNameForKey:NSLocaleIdentifier value:@"en_US"]);
// "English (United States)”

See Also

Accessing Locale Information by Key

- objectForKey:

Returns the value of the component corresponding to the specified key.

NSLocaleKey

The keys used to access components of a locale.