The least hacky way is via NSUserDefaults
: The locale is determined by AppleLocale
(the locale ID as a string) and the language is determined by the first match in AppleLanguages
(an array of language IDs); your app can override these defaults for your app only. To check if it's overridden by your app, you can use something like [defaults persistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]] objectForKey:@"AppleLocale"]
. To remove the override, use -removeObjectForKey:
.
Whichever way you do it, you'll probably have to relaunch the app when changing languages; OS X and iOS apps simply aren't designed to change language at runtime (on OS X, only newly launched apps see the language change; on iOS the system kills all apps to change language).
I added this feature to make switching languages easier for development/testing; I have no idea whether this will fail the App Store review process.
method_setImplementation(class_getInstanceMethod([NSLocale class], @selector(currentLocale)), (IMP)spoofedImpl);
?