• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: loading French strings being in English language
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Prev by Date: Re: IKImageView choppy?
  • Next by Date: strange horizontal line in scroll view
  • Previous by thread: Re: IKImageView choppy?
  • Next by thread: strange horizontal line in scroll view
  • Index(es):
    • Date
    • Thread