Language and locale automated testing on mobile apps

  • Share on Facebook
  • Share on Twitter
  • Share on LinkedIn
  • Share on HackerNews

Localization testing allows you to test your native mobile app on iOS and Android devices with various language and localization settings.
It is important to make sure that your mobile app works correctly on devices with other languages and locales, both functionally and in terms of design.

Some languages might use longer sentences than English, which might break your UI.
For example, you have a sentence in your app that fits perfectly inside the UI for English, but the translation in Portuguese is too long, causing the sentence to go beyond the allowed size.
Another example is where your app displays a number, currency, or date in a different format due to other locale settings. Setting various locale settings during your tests will allow you to test all these scenarios.

In this article we'll focus on how to perform language and locale testing, with both Appium, XCUItest (iOS) and Espresso (Android).

What is the difference between language and locale?

The terms locale and language are often used in the same context, but they have different meanings.

The term language indicates the language on the device. It is the language used in the UI of the device's OS and can often be changed in the Settings menu of your OS.
Examples of a language are: English, French, Portugese, Dutch, Spanish, Chinese and more. iOS supports more than 30 languages, while Android supports a larger amount of languages.

Locale refers to regional settings, for a specific country or place. This includes settings such as currency format, number format, or date formats.
Countries can share the same language, but have different locale settings.

To get a list of available locales on Android, you can use this snippet of code:

for (Locale locale : Locale.getAvailableLocales()) {
	Log.d("LOCALES", locale.getLanguage() + "_" + locale.getCountry() + " [" + locale.getDisplayName() + "]");

How to change the language in an Appium test?

Appium provides a language capability, which you can use to pass in the desired language code (ISO 639-1) of the app under test.

When you compile your IPA or APK file, you can indicate which languages you want to support and provide the translated content.
For Android, translated content usually appears in strings.xml files, while on iOS you can use XCode's localization features.

DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("language", "es");

To fetch a all translated strings for a specific language, you can use the app_strings command:

let appStrings = driver.getStrings("<language_code>");

How to change the locale in an Appium test?

To change the locale, you can use Appium's locale capability, which accepts region codes.

By changing the locale, you can test regional settings, such as currency formats, date formats, time and calendar formats.
All these settings are country/region specific and can be tested with Appium's locale capability.

DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("locale", "fr_CA");

Changing the language or locale will change the settings on a device level for Android, and on an app-level for iOS.

How to set a different language or locale with XCUITest?

XCUITest offers two arguments which you can use to set the language or locale:

  • -AppleLanguages
  • -AppleLocale

To use this in XCUITest, you can pass in a language or locale of your choosing like this:

XCUIApplication().launchArguments += [-AppleLanguages, (fr)]
XCUIApplication().launchArguments += [-AppleLocale, fr_FR]

In the example above, we set the language to French and the locale to France/French.
XCUITest will open the app with these settings. If your app has localized strings for this language, your app should display in the correct language.

Apple provides some more information about setting up and testing localized apps in their Testing your International App documentation.

How to change the language or locale with Espresso?

During an Espresso test, you can programmaticaly switch the language or locale of the app.
Please see the example below on how to achieve this:

private void setLocale(String language, String country) {
    Locale locale = new Locale(language, country);
    // here we update locale for date formatters

    // here we update locale for app resources

    Resources res = getContext().getResources();
    Configuration config = res.getConfiguration();
    config.locale = locale;
    res.updateConfiguration(config, res.getDisplayMetrics());

This function accepts a language and country, it will update the locale and resources during the Espresso test.

  • Share on Facebook
  • Share on Twitter
  • Share on LinkedIn
  • Share on HackerNews
TestingBot Logo

Sign up for a Free Trial

Start testing your apps with TestingBot.

No credit card required.

Other Articles

Automated Testing with Puppeteer

Puppeteer combined with a test framework provides a great way to run automated browser tests. Follow this guide for more information.

Read more
Tutorial on debugging Cypress tests

This article will focus on how to debug your Cypress tests with Cypress debugger and other developer tools.

Read more
Working with cookies - Selenium WebDriver

Handling cookies with Selenium WebDriver is a common task, since most websites use cookies. In this guide, we'll show you how to do this with Selenium.

Read more
How to use the Actions Class In Selenium

Selenium WebDriver comes with an Action Class, which allows you to simulate user input events, such as mouse and keyboard actions.

Read more
Handling Captcha during Automated Testing

We will discuss possible solutions to run automated tests with Captcha enabled websites.

Read more
Cypress and Cucumber Browser Testing

Cypress and Cucumber is a great combination to write clean and precise end-to-end browser tests.

Read more