user159971
user159971

Reputation:

Use specific localization in Cocoa app

How can you make your cocoa app use a specific locale / localization thats different from what the current locale says?

My app has a number of localizations and I would like to be able to choose the localization the app uses in a config file. How can I tell Cocoa which of the localizations to use?

Upvotes: 1

Views: 2215

Answers (4)

Vicky Stamatopoulou
Vicky Stamatopoulou

Reputation: 21

Hmmm could it be that AppleLocale expects an 'en' and not an "en_US"?

'en' works for me in the terminal so... I don't see why it should not be the same string here for you as well when setting it in your app

defaults write com.mycompany.myproduct AppleLocale 'en'

Upvotes: 2

xhan
xhan

Reputation: 6287

according to MAAD's answer. I tested in my app and found the only key that affects is AppleLanguages

so

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"en"] forKey:@"AppleLanguages"];

is enough.

Remember to restart your app to make user defaults take effects.

Upvotes: 1

user159971
user159971

Reputation:

I tried setting "AppleLocale" and "AppleLanguages" with something like the following:

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"en"] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] setObject:@"en_US" forKey:@"AppleLocale"];

It did nothing though, still the language and locale from the system preferences are used.

Upvotes: 0

user23743
user23743

Reputation:

Set the AppleLanguages array in the application's user defaults to contain the one you'd prefer to use, and set an appropriate AppleLocale string in the defaults too. Having said that, why use a localisation which isn't the one the user prefers?

Upvotes: 1

Related Questions