feat(mobile): run a device app in another language with app.locale (ENG-1252)
What
A device target can run its app in another language and region with app.locale, a BCP 47 tag. device.openApp takes the same option for one launch:
// e2e.config.ts
{
name: 'ios-fr',
engine: mobile({ platform: 'ios' }),
app: { bundleId: 'com.example.app', locale: 'fr-FR' },
}
// a test
await device.openApp('com.example.app', { relaunch: true, locale: 'ar-EG' });
- On iOS the locale becomes the launch's
AppleLanguagesandAppleLocalearguments. The device keeps its own language. - On Android the engine sets the app's own language (Android 13+) with this machine's
adbbefore the launch, and puts the app's earlier language back afterwards. - The engine refuses a locale it can't apply. That includes Android devices from a device provider, iOS devices on
testmu()andbrowserstack()(they drop launch arguments), and a device behind a remote agent-device daemon.
Why
ENG-1252. Before this, a test could set a language only on iOS, by writing launchArguments: { AppleLanguages: ['fr'], AppleLocale: 'fr_FR' } by hand. On a local Android device the only way was to change the device's language before the run. Detox (languageAndLocale), Maestro (--device-locale), and Appium (appium:language) each have an option for this. The migrate guides could map it only to hand-written Apple arguments on iOS, and to nothing on Android.
The locale is a property of the app under test, so it goes on the target's app, with an engine capability, rather than a flat mobile({ locale }) option (the design in ENG-1296).
How it works
- Core.
app.localeis a newTargetAppfield. At config load it must be a language tag (packages/core/src/config/app.ts:201), and the target's engine must declare the newappLocalecapability (packages/core/src/engine/index.ts:856). An engine without the capability fails withINVALID_CONFIG. On a web target, the error points atweb({ locale }). The capability travels through the engine manifest and protocol (engine/manifest.ts,engine/protocol/*,engine-manifest-v1.schema.jsonwith both fixtures). The locale reaches the engine asEngineAppInfo.locale, andlaunch()accepts it too (packages/core/src/core/launch.ts:123). - Config check in the mobile engine (
packages/mobile/src/engine.ts:131). The engine declaresappLocale: true.validateAppaccepts a tag with a language, a script, and a region only (packages/mobile/src/locale.ts:49), because a variant or an extension would not survive theAppleLocaleform. On iOS it refuses a target whoselaunchArgumentsalready setAppleLanguagesorAppleLocale. On Android it refuses abundleIdthat isn't a package name, becauseadbsets the locale per package.assertLocaleReachable(locale.ts:94) refuses a device this machine'sadbcan't reach: an Android device from a provider, and an iOS device from a provider that drops launch arguments. - Provider flag.
DeviceProvidergetslaunchArguments?: false(packages/mobile/src/provider.ts:151).testmu()andbrowserstack()set it, because agent-device's WebDriver backend dropslaunchArgswithout an error. Without the flag, the app would run in the device's own language and the test would pass in the wrong language. Expo, Revyl, and Limrun pass launch arguments through, so they don't set the flag. device.openApp(packages/mobile/src/surface.ts:924).- A
localeneedsrelaunch: true. Without it the call fails withINVALID_ARGUMENT, because a running app on Android would switch language at once while iOS ignores it. - The locale is the option's value, or else the target's
app.localeon a relaunch of the pinned app. - On iOS,
withLocaleArguments(locale.ts:303) appends-AppleLanguages (zh-Hans-CN) -AppleLocale zh-Hans_CNto the launch.
- A
- Android:
AndroidAppLocales(locale.ts:141).- Before the launch, and before the permissions so a refusal changes nothing, it checks for API 33 or newer. The first time it changes an app, it reads that app's own locales (
cmd locale get-app-locales). Then it runscmd locale set-app-locales <package> --locales <tag>. - It puts the saved locales back on the app's next fresh launch without a locale, on
device.closeApp()(surface.ts:1104), and at dispose (surface.ts:877). The dispose restore runs before the session closes and gets half the cleanup budget. - Every set, put-back, and restore runs one at a time, through
serialized(locale.ts:202). Without it, overlapping launches could leave a locale set. adbis found the way agent-device finds it:ANDROID_SDK_ROOT,ANDROID_HOME, the SDK's default folder, thenPATH(runAdb,locale.ts:264).- With
AGENT_DEVICE_DAEMON_BASE_URLset, the device is on another machine, so a launch with a locale fails withUNSUPPORTED_CAPABILITY.
- Before the launch, and before the permissions so a refusal changes nothing, it checks for API 33 or newer. The first time it changes an app, it reads that app's own locales (
- Docs.
docs/mobile.mdx("Run the app in another language") and theDeviceProvidercontract; the config, core, engine, engine-protocol, and mobile reference pages; the Detox, Appium, and Maestro migrate tables;skills/e2e/references/setup.md. A changeset patch-bumps core, e2e, every engine (for the contract field), testmu, and browserstack.@e2e-dev/mobilenow needs core and e2e 0.25.1 or newer.
Alternative not taken: change the whole Android device's language. That changes every app on the device, and the device for any other session sharing it. The per-app locale touches only the app under test.
The guide section is shorter than the first draft. Some details moved to the reference page's "Launch arguments and permissions", which the guide now links: the XCTest phone refusal, the remote-daemon refusal, the extension example, and the exact restore points.
Review findings not taken:
- Write locales per Android user (
--user). Nothing in e2e or agent-device switches users during a run. - Add
app.localeto the replay cache key. The key already has the target name, and the docs use one target per language.launchArgumentsandpermissionsaren't in the key either. A stale recording misses its locators instead of answering wrong.
Issue
ENG-1252
Verified
Ran it locally: yes
A scratch project ran the built CLI against the Settings app. Android ran on a dedicated API 36 emulator (Pixel 6) and iOS on a new iPhone 17 Pro simulator (iOS 27.2) whose own language is Korean.
| Check | Android | iOS |
|---|---|---|
app.locale: 'fr-FR' | "Rechercher dans les paramètres" | "Réglages" |
openApp({ relaunch: true, locale: 'ja-JP' }), then app.open() | "設定を検索", then French again | "設定", then "Réglages" |
No app.locale; openApp with fr-FR, closeApp(), app.open() | French, then "Search Settings" | French, then "설정" (device language) |
openApp({ locale }) without relaunch | INVALID_ARGUMENT | INVALID_ARGUMENT |
Settings had its own de-DE before the run | [de-DE] after the run | n/a |
before: Locales for com.android.settings for user 0 are [de-DE]
✓ |android| tests/locale.e2e.ts > Settings opens in the target locale 4.56s
✓ |android| tests/override.e2e.ts > openApp locale overrides app.locale for one launch 6.71s
✓ |ios| tests/locale.e2e.ts > Settings opens in the target locale 5.36s
✓ |ios| tests/override.e2e.ts > openApp locale overrides app.locale for one launch 11.00s
Tests 4 passed (4)
after: Locales for com.android.settings for user 0 are [de-DE]
refused: INVALID_ARGUMENT device.openApp({ locale }) needs relaunch: true: a locale takes effect when the open launches the app fresh
The refusals and the restore races were checked with unit tests only, because they need a provider, a remote daemon, or precisely timed adb calls. These include the provider refusals, the remote daemon, Android older than 13, an adb that hangs at dispose, overlapping launches, and a launch by display name. The tests use a scripted adb, and the overlap test fails without the serialization fix (expected 'ja-JP' to be 'de-DE').
Benchmark: not measured. pnpm bench:ab runs only the web benchmark, and a launch without a locale runs no new device command (presetAndroidLocale returns at once, surface.ts:968).
The videos below are the override test (ja-JP for one launch, then back to fr-FR) on Android and on iOS.
https://github.com/user-attachments/assets/c20cd08e-e89c-4dc3-a62e-c7bf3763d004
https://github.com/user-attachments/assets/00769db9-fff4-49a5-9559-11ec7118bb40
Checklist
- Changeset added (
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only. - Breaking change: title carries
!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md). Not breaking: the field and the capability are optional. - Docs updated in the same PR: the
docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.
🤖 Generated with Claude Code