In order to present the proper menu text and some other aspects of the UI I am trying to get the current user's country and keyboard language.
I know the locale (via the env. variable) but I can't find a way to get these two pieces of info.The code is in C for Mac OS X. I can use Co开发者_StackOverflowcoa API to get them but they need to be called from C. Any ideas?
Thank you!
Use CFLocaleCopyCurrent
, CFLocaleGetValue
and CFLocaleCopyPreferredLanguages
(note that the preferred language may not match the locale's language). See the documentation.
Edit: ok, here's some sample code.
#include <CoreFoundation/CoreFoundation.h>
#include <stdio.h>
int main (int argc, char **argv)
{
CFLocaleRef loc = CFLocaleCopyCurrent();
CFStringRef countryCode = CFLocaleGetValue (loc, kCFLocaleCountryCode);
CFStringRef countryName = CFLocaleCopyDisplayNameForPropertyValue (loc, kCFLocaleCountryCode, countryCode);
CFShow(countryCode);
CFShow(countryName);
CFArrayRef langs = CFLocaleCopyPreferredLanguages();
CFStringRef langCode = CFArrayGetValueAtIndex (langs, 0);
CFStringRef langName = CFLocaleCopyDisplayNameForPropertyValue (loc, kCFLocaleLanguageCode, langCode);
CFShow(langCode);
CFShow(langName);
}
精彩评论