Skip to content

Changing Locale and Language

Joshua Moody edited this page Mar 15, 2016 · 2 revisions

You can change the Language and Locale settings by telling Calabash to launch the app with arguments.

There are three steps to testing Localizations:

  1. You application needs to be localized for the language and locale you are testing.
  2. The target device needs to be configured to support the language and locale.
  3. You must tell Calabash to launch your application with special launch arguments.

You must be responsible for Step 1: Localizing your application.

Step: 2 Preparing the Target Device

Physical Devices

On physical devices, you must set the language and locale manually. You can get configure your device to support more than one keyboard language and set the preferred language order. This is all done in your Settings.app.

Xamarin Test Cloud

Submit your tests with the --locale option:

$ test-cloud submit < ARGS > --locale "de"
iOS Simulators

On simulators, you can tell the simulator to launch in a specific locale with a preferred language.

# Set the simulator language to Swiss German and locale to Swiss French
# Languages use a "-"  separator for regional varieties
# Locales use a "_" separator for regional varieties
$ calabash-ios sim locale de-CH fr_CH

We have several example projects where we demonstrate launching the iOS Simulators in different languages and locales.

Step 3: Launch Arguments

You can set either the language or locale or both.

module Calabash::Launcher
  @@launcher = nil

  def self.launcher
    @@launcher ||= Calabash::Cucumber::Launcher.new
  end

  def self.launcher=(launcher)
    @@launcher = launcher
  end
end

Before do |scenario|
  launcher = Calabash::Launcher.launcher
  options = {
    # Launch with Spanish as the primary language
    :args => ["-AppleLanguages", "(es)"]

    # Launch with Swiss German as the primary language and
    # Swiss French as the locale.
    :args => ["-AppleLanguages", "(de-CH)",
              "-AppleLocale", "fr_CH"]

    # Launch with Russian as the primary language and English
    # as the second language.
    :args => ["-AppleLanguages", "(ru, en)"]

    # Launch with German as the locale
    :args => ["-AppleLocale", "de"]
  }

  launcher.relaunch(options)
  launcher.calabash_notify(self)
end

Thanks @yakovsh.

This NSHipster page has examples of other launch arguments:

Clone this wiki locally