views:

253

answers:

2

I'm developing an application that should support two languages: English and French. However because English translation is not done yet we want to deploy it in French only and later on add English translation later on.

The problem is that I don't want to strip English language out of my code since some parts are already done, there are different NIBs for that language etc. Instead I'd just want english language to be temporary disabled in my app.

What I did is I put this code as the first instruction of

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[NSArray arrayWithObjects:@"fr", nil] forKey:@"AppleLanguages"];
[defaults synchronize];

It works fine except for one thing. When you launch the application for the first time after installation it's still in English. That's probably because AppleLanguages preference was not yet set for it. After I quit the application and start it again it's being displayed correctly in French.

Does anyone knows a fix so that French language was applied also on the first run?

+1  A: 

Sounds messy. Why not just uncheck the unfinished English resources from the target, so they won't get deployed? Also, have you looked into the CFBundleDevelopmentRegion setting in Info.plist?

Matt Martel
A: 

I ran into the same issue, and the only way I could fix it was to have the piece of code at the earliest stage in the app, i.e. in main.c:

 int main(int argc, char *argv[]) {

     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
     [defaults setObject:[NSArray arrayWithObjects:@"fr", nil] forKey:@"AppleLanguages"];
     [defaults synchronize];

     int retVal = UIApplicationMain(argc, argv, nil, nil);

     [pool release];
     return retVal;
 }

I'm not really sure it's a good practice but it worked as expected in my case.

romrom