Last Updated: September 09, 2019
·
4.3K
· adamyanalunas

Automate localization testing in Xcode

Is your iOS application localized? Do you test that your NSLocalizedStrings actually work? You should. But changing the language in the iOS Simulator is annoying and, like all human actions, error prone. Let's leave it to Xcode.

Note This is just for languages. If you need to force a region I assume there are corresponding flags but I'm not sure what they are.

A scheme can pass language arguments when running that will tell the Simulator to launch with a specific language. Make a scheme for every language you want to test and for each one add these arguments:

  • -AppleLanguages
  • \(en\)

Yes, you have to escape the parenthesis. Just change the en to whatever ISO 639-1 language code is appropriate.

The Simulator will launch and run the app in the specified language. Hooray! But, wait, how does that help you test?

In your test suite of choice you can use the following line to extract the currently-used language code.

NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];

This will report back en, es, de, yada yada.

Remember, keep your tests DRY and architect accordingly.