PDA

View Full Version : CFLocaleCopyCurrent ????




satyam90
Sep 25, 2008, 02:30 AM
I am using Obj C with Cocoa framework.
The language on my Mac is English.

I am trying to get the language preference of my Mac using the following code:

userLocaleRef = CFLocaleCopyCurrent();
CFShow(CFLocaleGetIdentifier(userLocaleRef));

It is displaying en_IN when I am running the application from console. Its fine.

Now I changed my language to simple chinese using System PReferences -> International and restarted my Mac.

Still above code is displaying en_IN only.
How to get the language code of my Mac to which it is currently set?



kainjow
Sep 25, 2008, 08:23 AM
Not sure why it's not working, but since you're using Cocoa you can use NSLocale instead of the CF functions.

Also when you change the localization settings in System Preferences you only need to relaunch the app, not restart. Makes it a bit easier for testing :)

gnasher729
Sep 25, 2008, 12:04 PM
Not sure why it's not working, but since you're using Cocoa you can use NSLocale instead of the CF functions.

Also when you change the localization settings in System Preferences you only need to relaunch the app, not restart. Makes it a bit easier for testing :)

I think the "language" setting only changes the order in which different language resources in an application are chosen; this cannot give you chinese language unless you have chinese resource. I would also check what happens when the format options are changed.

Sayer
Sep 25, 2008, 04:11 PM
Change the Info.plist part:

<key>CFBundleDevelopmentRegion</key>
<string>English</string>

That's what sets the app's default language.

satyam90
Sep 30, 2008, 02:40 AM
I coldn't find code how to use NSLocale to get current language of Mac..........can some body tell me how to?