开发者

Setting default language for iPhone app on first run

开发者 https://www.devze.com 2023-01-01 10:00 出处:网络
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 o

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?


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.


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消