Overriding the default iOS localization language for your app
With an increasingly globalized world, it is now an important requirement to support your iOS app’s user interface language in languages other than just English. This is especially true if your app is deployed in many other countries where English may not be a popularly spoken language. But it is also true if your user prefers to use a different language in your app for their personal preference.
In either case, the user would have the International setting set on their iPhone accordingly i.e. to English, German, French etc. But what if you would like to give your user finer control - they may prefer their iPhone set to using English but your app in a different language. In that case, we need to override iOS’s default language in our app. Recently, I had to do this for my app ADIO.
When an app starts, iOS creates the NSUserDefaults object for it and seed the app with it. This instance of NSUserDefaults contains a special key called AppleLanguages. This key points to an ordered array that contains a list of language codes. Starting with the first language code in this list, your bundle will be searched for the matching Localizable.strings file.
In your main.m file, insert the following to set French as your app’s language. This is an example; you can insert any language code that your app supports.
#import <UIKit/UIKit.h> #import "AppDelegate.h"
int main(int argc, char *argv[]) {
@autoreleasepool {
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:@["fr", @"en", nil] forKey:@"AppleLanguages"]; [defaults synchronize];
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
} }
It’s important to do this in the main.m, if you wait until the app delegate’s applicationDidFinishLaunching callback then it will be too late for that launch of the app. Though on a subsequence launch, the language change would be picked up. Doing so in main.m, avoids that problem and the change is immediate.
Happy Coding!
good bye, adiós, abschied, 再见, الوداع, au revoir










