Skip to main content
Sets the language Encore serves its copy and offers in. It outranks the device language on every request the SDK makes. Use it when your app has its own language picker, or when the user’s app language differs from their device language.
New in the React Native SDK release that pins native 2.3.0.

Signature

Parameters

Behavior

  • The SDK keeps the language on the device until you call clearLanguage(), so it survives relaunches. Encore never stores it on its servers.
  • It is a preference of the device, not user state, so reset() and logout leave it in place.
  • When the language changes, the SDK fetches its configuration and offers again.
  • An invalid tag rejects the returned Promise before anything reaches the native SDK. See Errors.
  • A failure inside the native SDK logs a warning, and the Promise still resolves, like every other Encore call. The same happens when a newer JavaScript bundle runs on an app binary built before this release, for example after an over-the-air update. When the native module is not linked, for example in Expo Go, the call resolves and does nothing.
  • The language is served only when your app has it enabled. Otherwise Encore falls back to the device languages, then your app’s default language. See Localization.
  • The device language is still sent as Accept-Language. This call adds the override that outranks it.

Errors

Both reject before the call reaches the native SDK, so nothing changes.

Replaces the language attribute

Setting the language through the language attribute is deprecated. It still works and calls setLanguage() for you, logging a warning once, and it is removed at the next major release. A language saved through the attribute on an earlier release carries over the first time the new SDK starts. Unlike setLanguage(), the attribute and the carry-over still accept a locale identifier and turn it into a tag, so pt_BR becomes pt-BR and de_DE@currency=EUR becomes de-DE. See the deprecated attribute. A language set through the attribute is stored as the same override, so it also survives reset().

Usage

Call it from your app’s own language picker, and call clearLanguage() when the user picks “System default”: