Setting the default language for the iPhone application on first launch

I am developing an application that should support two languages: English and French. However, since the translation into English is not yet complete, we want to deploy it only in French, and later add the English translation later.

The problem is that I do not want to strip English from my code, because some parts have already been completed, there are different NIBs for this language, etc. Instead, I just want English to be temporarily disabled in my application.

What I did, I put this code as the first instruction

- (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. When you launch the application for the first time after installation, it is still in English. Probably because preference AppleLanguageshas not yet been established. After I left the application and started it again, it displays correctly in French.

Does anyone know a fix for the French language to be applied on first run?

0
source share
2 answers

Sounds random. Why not just unplug the unfinished English resources from the target, so they won’t be deployed? Also, have you looked at the CFBundleDevelopmentRegion parameter in Info.plist?

+3
source

, , , , , 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;
 }

, , , .

+10

Source: https://habr.com/ru/post/1532088/


All Articles