Re: Human readable locale names.
Re: Human readable locale names.
- Subject: Re: Human readable locale names.
- From: mmalcolm crawford <email@hidden>
- Date: Thu, 18 Aug 2005 04:01:01 -0700
On Aug 17, 2005, at 5:44 PM, Óscar Morales Vivó wrote:
How can I get the human-readable version of a locale from its
NSLocale object? I don't see any key for it in the constants
listing and I need to display a drop list of some of them,
preferably in human-readable format.
What I want is, instead of displaying "es_ES" or "en_US" to display
"Español (España)" and "U.S. English" (like in the System
Preferences International panel more or less).
The following works, although I'm not sure if it's the best way
(suggestions and corrections welcome -- although note that error
conditions are deliberately ignored for compactness).
#import <Foundation/Foundation.h>
#import <CoreServices/CoreServices.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *identifier = [[NSLocale currentLocale] localeIdentifier];
char localeString[12];
BOOL ok = [identifier getCString:localeString maxLength:12
encoding:NSASCIIStringEncoding];
OSStatus status;
LocaleRef locale;
// status = LocaleRefFromLocaleString (localeString, &locale);
status = LocaleRefFromLocaleString ("es_ES", &locale);
LocaleRef displayLocale;
// status = LocaleRefFromLocaleString(localeString,
&displayLocale);
status = LocaleRefFromLocaleString("es_ES", &displayLocale);
UniCharCount maxNameLen = 256;
UniCharCount actualNameLen;
UniChar displayName[256];
status = LocaleGetName (locale,
0, // LocaleOperationVariant opVariant
kLocaleAndVariantNameMask, // LocaleNameMask nameMask
displayLocale,
maxNameLen, // UniCharCount maxNameLen
&actualNameLen, // UniCharCount * actualNameLen
displayName); // UniChar displayName[]
NSString *displayString =
[NSString stringWithCharacters:displayName
length:actualNameLen];
NSLog(@"identifier: %@", identifier);
NSLog(@"localeString: %s", localeString);
NSLog(@"displayString: %@", displayString);
[pool release];
return 0;
}
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden