> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encorekit.com/llms.txt
> Use this file to discover all available pages before exploring further.

# setLanguage()

> Set the language Encore serves copy in, overriding the browser language until you clear it

Sets the language Encore serves its copy and offers in. It outranks the browser 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 browser language.

<Note>
  New in the web SDK release that includes language support.
</Note>

## Signature

```typescript theme={null}
function setLanguage(tag: string): void
```

## Parameters

| Parameter | Type | Description |
| - | - | - |
| `tag` | string | A well-formed BCP-47 language tag, for example `es`, `es-MX`, or `pt-BR`. The SDK normalizes its case, so `PT-br` becomes `pt-BR`, and Encore keeps only the language part, so `es-MX` serves `es`. See [Language tags](/publishers/concepts/localization#language-tags) for what is accepted |

## Behavior

* The SDK keeps the language in the browser's `localStorage` until you call [`clearLanguage()`](./clear-language), so it survives page reloads and later `configure()` calls. Where `localStorage` is unavailable it falls back to `sessionStorage`, then to memory for the current page. Encore never stores it on its servers.
* It is a preference of the browser, not user state, so [`reset()`](./reset) and logout leave it in place.
* When the language changes, the SDK drops its cached copy and offers and fetches its configuration again right away. The web SDK does not load offers ahead of time, so they load in the new language on the next [`show()`](./show).
* Setting the language already in effect does nothing.
* An invalid tag, such as `pt_BR` or `english`, is ignored with a console warning, whatever your log level. `setLanguage()` never throws, and the language already in effect stays.
* The language is served only when your app has it enabled. Otherwise Encore falls back to the browser languages, then your app's default language. See [Localization](/publishers/concepts/localization).
* The browser language is still sent as `Accept-Language`. This call adds the override that outranks it.
* Call it after [`configure()`](./configure). Before `configure()` the call does nothing, and `configure()` takes no language.

## Replaces the `language` attribute

Setting the language through the `language` attribute is deprecated, and it is removed at the next major release. It still works: [`setUserAttributes()`](./set-user-attributes) and [`identify()`](./identify) take `language` out of the attributes, call `setLanguage()` with it, and log one warning per page load. `identify()` does this after it has switched to the new user, so copy is fetched again for that user. The language is no longer returned by `getUserAttributes()`.

A language saved through the attribute on an earlier release moves into the override the first time `configure()` runs, and is removed from the saved attributes. A language you already set with `setLanguage()` wins, and a saved value that is not a valid tag is dropped. 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](/publishers/concepts/localization#the-language-user-attribute-is-deprecated). 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":

```javascript theme={null}
import Encore from '@encorekit/web-sdk';

Encore.configure({ apiKey: 'pk_live_your_key' });

function onLanguageChanged(code) {
  if (code) {
    Encore.setLanguage(code);
  } else {
    Encore.clearLanguage();
  }
}
```

## Related

* [clearLanguage()](./clear-language): go back to the browser language
* [setUserAttributes()](./set-user-attributes): the deprecated `language` attribute
* [Localization](/publishers/concepts/localization): how Encore picks the language it serves


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.