Re: loading French strings being in English language
Re: loading French strings being in English language
- Subject: Re: loading French strings being in English language
- From: Mark Ritchie <email@hidden>
- Date: Sun, 01 Aug 2010 02:35:05 -0700
Hey!
On 31/Jul/2010, at 10:41 PM, cocoa learner wrote:
> Any example or code snippet will help here.
Sure! ;-)
// get the shared defaults object
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
// remove any previous setting for languages
[userDefaults removeObjectForKey:@"AppleLanguages"];
// lookup the current array of languages
// Note: if you think this returns null because of the line above, you should read the docs on NSUserDefault domains! ;-)
NSArray *languages = (NSArray *)[userDefaults objectForKey:@"AppleLanguages"];
// filter the list of languages to include only ones which you support
// give the user a UI to select the language which they would like
// change the language array so that the selected language is the first entry
//
// for my example, I swap the first and second languages (result depends on your setup but you get the idea.)
NSMutableArray *mutableLanguages = [languages mutableCopy];
[mutableLanguages exchangeObjectAtIndex:0 withObjectAtIndex: 1];
// save the updated languages
[userDefaults setObject:mutableLanguages forKey:@"AppleLanguages"];
Now whenever NSLocalizedString() or it's relatives do a lookup, they will use the 0th language in "AppleLanguages".
This solution stores the selected language array in the application's private defaults so it will persist across invocations of the application and is quite independent of the system wide user selected language.
Hope that helps!
M.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden