How to get system language in ISO 639-2 format of MAC OS using cocoa?
I want to retrieve the system language of a Macintosh in ISO-639-2 format (that 开发者_运维技巧is, in three character format).
Currently, I'm trying to use [NSUserdefault objectforkey:@"Applelanguages"]
. This returns the Language code in 2 character format.
Whatever API I end up using, it should support MacOS X versions from 10.3.9 forward.
The relevant sections of the document are Internationalization Guide, another section of the same guide, and CFLocale reference. Unfortunately I don't think there's a standard API provided which convert 639-1 to 639-2. As explained there, OS X uses a mixture of both, and the canonical form used by the OS can be obtained by CFLocaleCreateCanonicalLanguageIdentifierFromString
. But this is not what you want, unfortunately.
I would suggest you to process the table given here into an NSDictionary yourself.
For people needing this and don't want to process the table themselves, I created a category on NSLocale which should probably work on OS X also.
精彩评论