gran_profaci
gran_profaci

Reputation: 8463

Is there a way to change the locale/language on an iOS Simulator through code?

I was searching for a way to change the iOS device Locale without having to go through the settings and importing some new framework. Just a simple script or so would be great, or even a piece of code. I was wondering if there was something like :

[[NSLocale currentLocale] setLocale:@"WhateverLocale"];

Upvotes: 0

Views: 781

Answers (1)

bgfriend0
bgfriend0

Reputation: 1152

This may or may not fulfill your needs, but one way to gain programmatic access over the app's current locale is to override the AppleLanguages key in NSUserDefaults. For example, to change to French:

[[NSUserDefaults standardUserDefaults] setObject:@[ @"fr" ]
                                          forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];

The downside to this approach is that you need to close and reopen the app for the change to take effect.

Note, to return to the system default, simply call:

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppleLanguages"];

Upvotes: 1

Related Questions