# Languages (https://docs.salla.dev/twilight/react/sdk/languages)



Read this when you need a text the SDK or a `salla-*` web component shows, or want to change one.

`Salla.lang` holds the **store's** texts: the messages the SDK shows and the labels inside the web components.
They are not your theme's texts. For those, use [`useTranslation`](https://docs.salla.dev/twilight/react/hooks/use-translation) and your locale files, as [Languages and RTL](https://docs.salla.dev/twilight/react/guide/languages-and-rtl) shows.

## Read a text [#read-a-text]

Pass the key. The SDK looks it up in the current language, then in English:

```ts
Salla.lang.get('common.messages.required_fields');
Salla.lang.get(key, { name: 'Sara' });                   // fills :name in the text
Salla.lang.getLocale();                                  // 'ar'
```

A key that exists in neither language comes back as the key itself.

## Wait until the texts load [#wait-until-the-texts-load]

The texts load after the SDK starts. Read them once they are there:

```ts
await Salla.lang.onLoaded();
const label = Salla.lang.get('pages.cart.free_shipping');
```

`onLoaded` resolves at once when the texts are already loaded. They fire `languages::translations.loaded` when they arrive.

## Change or add texts [#change-or-add-texts]

| Method                                         | Does                                   |
| ---------------------------------------------- | -------------------------------------- |
| `Salla.lang.set(key, text)`                    | Changes a text in the current language |
| `Salla.lang.add(key, { ar, en })`              | Adds a key in several languages        |
| `Salla.lang.addBulk({ key: { ar, en }, ... })` | Adds several keys at once              |

```ts
Salla.lang.add('pages.order.new_order', { ar: 'طلب جديد', en: 'New Order' });

Salla.lang.addBulk({
  'pages.order.new_order': { ar: 'طلب جديد', en: 'New Order' },
  'pages.product.new_product': { ar: 'منتج جديد', en: 'New Product' },
});
```

Use these to change a label inside a web component, after `onLoaded`. The change lasts until the page reloads.

## Gotchas [#gotchas]

* Do not use `Salla.lang` for your theme's own strings. Your locale files load on the server with the page, while `Salla.lang` exists only in the browser.
* `set` changes the current language only. Pass the key without a language: `set('pages.order.new_order', 'New Order')`.
* The engine keeps the SDK's language in step with the URL. Do not change it yourself with `Salla.lang.setLocale`.

## See also [#see-also]

* [Languages and RTL](https://docs.salla.dev/twilight/react/guide/languages-and-rtl)
* [`useTranslation`](https://docs.salla.dev/twilight/react/hooks/use-translation)
* [Overview](https://docs.salla.dev/twilight/react/sdk)
