discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem running hello-objc-gnustep example in gettext


From: Richard Frith-Macdonald
Subject: Re: Problem running hello-objc-gnustep example in gettext
Date: Sat, 21 Aug 2010 14:12:05 +0100

On 21 Aug 2010, at 11:17, David Chisnall wrote:

> On 21 Aug 2010, at 11:08, Nicola Pero wrote:
> 
>> I don't think there is an easy way to change the language on the fly for a 
>> single invocation of an application.
> 
> 
> Is there a reason why your original suggestion, invoking like this, doesn't 
> work?
> 
> $ myApp -NSLanguages='(French, Italian)'

That's fine ... but I think the idea was to do it programatically from within 
the app itsself.

Using -setUserLanguages: is probably wrong ... it's for setting a persistent 
default for any/all apps run by the current user.

I imagine that what's wanted is a temporary setting for the current application.
In which case the simple solution is to use -registerDefaults: to set the 
NSLanguages user default to an array containing the desired language name.
eg.

  [[NSUserDefaults standardUserDefaults] registerDefaults: [NSDictionary 
dictionaryWithObjectsAndKeys: [NSArray arrayWithObject: @"French"], 
@"NSLanguages", nil]];

but that is the lowest precedence setting ... if someone has set a different 
value for NSLanguages in NSGlobalDomain then that other value will be used.

If you want to override any defaults set anywhere else ... then the code is a 
bit more complex as you need to set a default in a new domain and make that 
domain have highest precedence.
The precedence of domain for searching defaults is controlled by the search 
list, so you need to put the new domain at the start of the list.

eg. (untested code, but it shows the idea)

NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
NSMutableArray *list = [[[defs searchList] mutableCopy] autorelease];

[defs setVolatileDomain: [NSDictionary dictionaryWithObjectsAndKeys: [NSArray 
arrayWithObject: @"French"], @"NSLanguages", nil]; forKey: @"MyDomain"];
[list insertObject: @"MyDomain" atIndex: 0];
[defs setSearchList: list];


reply via email to

[Prev in Thread] Current Thread [Next in Thread]