Xcode Quick Tip – Testing your layout for localization

April 7, 2018
xcode testing localization

The Zendesk Support app supports a number of languages, meaning that the strings we display in the app change, depending on the device language set.

Recently we encountered buggy UI component positioning when the device language was changed from the default language (English). This is shown below with Dutch.

UI component (UISwitch) incorrectly positioned due to ambiguous constraints

Due to some ambiguous auto-layout constraints, the UILabel containing the string increases in size when the string grows in length, causing the next UI element, a UISwitch, to be pushed outside the bounds of the containing view.

We needed to repeatedly reproduce the issue as we investigated and resolved this bug. Rather than changing the device language, which is cumbersome, we stumbled upon a testing method known as pseudolocalization.

Pseudolocalization is a testing method used to test internationalization which involves replacing the default language strings with altered versions. For exmaple, we might replace “Login” with “Login Login Login Login”.

We then discovered a very useful option in the Xcode scheme editor which enabled us use pseudolocalization to test our layout, shown below.

Xcode scheme setting allowing us to use pseudolocalization to test layout

Using this setting, all strings in the app are replaced with pseudo-translations consisting of the original string repeated twice. Shown below is the app running with this setting enabled, which results in the default strings being replaced by pseudo-translations.

Pseudo-translations being displayed, highlighting an auto-layout bug

Using the pseudolocalization Xcode scheme setting, we were able to reproduce the reported issue quickly and implement a fix! 🎉 Our updated UI is shown below.

Pseudo-translations being displayed with the auto-layout bug fixed!


In Summary

  • Pseudolocalization is a testing method used to test internationalization which involves replacing the default language strings with altered versions.

  • Xcode includes a scheme setting which allows us to test our UI layouts using pseudolocalization.

  • Pseudolocalization should be part of normal feature development.