Internationalization of the iOS database: changing the language at runtime

We know this is an old and painful question.

If you do not know, let me briefly describe the problem. Suppose we have an application, and we want to use the built-in xcode localization using NSLocalizedString (), the standard method recommended by Apple. Everything is fine until you want to change the language at runtime. You cannot force the application to use a different language, Apple recommends always using the system language or manually loading and managing resources (of course, we do not want to do this).

From here you have very few alternatives.

1) User default

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"de", nil] forKey:@"AppleLanguages"];

This key is undocumented, but it is allowed. The problem with this method is that the language will be installed only after restarting the application. Unfortunately, you cannot restart the application yourself, you will have to ask the user to do this.

2) Use some custom macros, as in this example . The problem with this method is that - you will have to adapt your entire codebase - the storyboards and nib files will not be translated - Localization will not work at all, because the genstring utility used by Xcode only recognizes NSLocalizedStringXXX macros, or you will end up with manually genstring using some stage after assembly.

3) , , NSBundle. , localizedStringForKey NSBundle, . :

#import "BundleLocalization.h"
...
[[BundleLocalization sharedInstance] setLanguage:@"fr"];

[BundleLocalization sharedInstance].language = @"de";
NSLog(@"Application language: %@", [BundleLocalization sharedInstance].language);

, , . .

, - Apple Policy?

+4

All Articles