A quick tip for switching between localizations when testing. Updated 28-December-2013 to include details on setting the locale
Changing the Language Settings
If you have done any work with localizing an application I am sure you are familiar with changing the language of the simulator or a device from the Settings app:
Changing this setting back and forth between the different languages you need to support is tiresome if you do it manually. Luckily there is a build argument you can use to force the language at runtime.
Forcing the Required Language at Runtime
To force an application to run with a specific localization language you can pass the AppleLanguages argument to the application on launch. The argument takes the desired language as a parameter so to force the language to Spanish you would use the following:
The syntax is a little fussy:
- Don’t forget the leading hyphen “-”.
- There is a space after -AppleLanguages
- The required language is in parentheses
- You can specify the language using the long form (e.g. Spanish) or using the country code (e.g. es). If you are not sure of the value just look at the name of the lproj directory that Xcode created to hold the language files for that localization.
- If required you can surround the parameter in quotes - “(Spanish)” but you should only need to do that if you have spaces in the language identifier.
- If you pass more than one AppleLanguages parameter it will ignore all but the first.
Setting the Required Locale
In addition to setting the language you can also set the locale using the AppleLocale argument:
Setting Launch Arguments
The easiest way to pass launch arguments when running from Xcode is to add them to the scheme. You can edit the current scheme from the Product > Scheme > Edit Scheme menu (or use ⌘< or option-click the Run button).
I find it useful to add an AppleLanguages argument to the Run phase of a scheme for each localization and enable the one I need. For example: