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:31:58 -0700
On 18 Aug 2005, at 04:01, mmalcolm crawford wrote:
The following works, although I'm not sure if it's the best way
Hmm, this may be better since it displays the result in the user's
chosen language...
#import <Foundation/Foundation.h>
#import <CoreServices/CoreServices.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
LocaleRef currentLocale;
LocaleRef displayLocale;
BOOL ok;
OSStatus status;
NSString *currentLocaleIdentifier = [[NSLocale currentLocale]
localeIdentifier];
char currentLocaleString[12];
ok = [currentLocaleIdentifier getCString:currentLocaleString
maxLength:12
encoding:NSASCIIStringEncoding];
status = LocaleRefFromLocaleString (currentLocaleString,
¤tLocale);
NSString *currentLanguageIdentifier = [[[NSUserDefaults
standardUserDefaults]
stringArrayForKey:@"AppleLanguages"] objectAtIndex:0];
char displayLocaleString[12];
ok = [currentLanguageIdentifier getCString:displayLocaleString
maxLength:12
encoding:NSASCIIStringEncoding];
status = LocaleRefFromLocaleString(displayLocaleString,
&displayLocale);
UniCharCount maxNameLen = 256;
UniCharCount actualNameLen;
UniChar displayName[256];
status = LocaleGetName (currentLocale,
0, // LocaleOperationVariant opVariant,
kLocaleAndVariantNameMask, // LocaleNameMask nameMask,
displayLocale,
maxNameLen, // UniCharCount maxNameLen
&actualNameLen, // UniCharCount * actualNameLen
displayName); // UniChar displayName[]
NSString *displayString = [NSString
stringWithCharacters:displayName length:actualNameLen];
NSLog(@"currentLocaleIdentifier: %@", currentLocaleIdentifier);
NSLog(@"currentLanguageIdentifier: %@", currentLanguageIdentifier);
NSLog(@"localeString: %s", currentLocaleString);
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