I'm interested in allowing my users to choose the language / locale my app appears to them in. I have figured out how to load the right bundle, choose the correct strings files, etc. However, some system items I still seem to have no control over. Switch controls, for example.
Is there any way for me to tell the system that this app should now behave in a specific language, rather than the user's current system setting?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With