• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Human readable locale names.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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, &currentLocale);


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


  • Follow-Ups:
    • Re: Human readable locale names.
      • From: mmalcolm crawford <email@hidden>
References: 
 >Human readable locale names. (From: Óscar Morales Vivó <email@hidden>)
 >Re: Human readable locale names. (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: Human readable locale names.
  • Next by Date: How to make sure that particular item is visible in NSOutlineView
  • Previous by thread: Re: Human readable locale names.
  • Next by thread: Re: Human readable locale names.
  • Index(es):
    • Date
    • Thread