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 iOS SDK 2.3.0. React Native and Flutter forward it from the 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.
  • Setting the language already in effect does nothing.
  • An invalid tag, such as pt_BR or english, is logged and ignored. setLanguage(_:) never throws, and the language already in effect stays.
  • Before configure(), the call logs that the SDK is not configured 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.

Replaces the language attribute

Setting the language through UserAttributes(language:) is deprecated. It still works: passing language: to the UserAttributes initializer calls setLanguage(_:) for you, logging a warning once per launch, and it is removed at the next major release. The language is no longer sent as an attribute, and UserAttributes.language is now read-only. 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”: