> Portal Navigation:
>
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt
## Resource: Implement Localization in your App Extensions
## Article: Implement Localization in your App Extensions
## Article Link: https://dev.wix.com/docs/build-apps/launch-your-app/localization/implement-localization-in-your-app-extensions.md
## Article Content:
# Implement Localization in your App Extensions
When localizing your app, you may need to display text in the user's chosen language. Users can set different languages for different interfaces. For example, they may choose one language for the dashboard, but allow their site users to set a different language for the site. This means your app needs to retrieve the chosen settings for each [extension](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/about-extensions.md).
The essentials SDK's [`i18n` submodule](https://dev.wix.com/docs/sdk/core-modules/essentials/i18n.md) allows app extensions to access the active language and locale settings of a site's [interfaces](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/about-extensions.md#frontend-interfaces).
This article outlines the recommended steps for using the SDK to display localized text in different parts of your app.
> **Note:** This article uses the [FormatJS' `react-intl` package](https://formatjs.io/docs/react-intl/), but you may use any other localization library. Make sure to install your chosen package in your app before starting to code.
## Step 1 | Prepare translations
For each language your app supports, create a JSON file containing all your app's strings.
> **Notes:**
> - You can save your JSON files wherever you like in your code.
> - Anything contained in `{}` represents variables. The [Intl MessageFormat](https://formatjs.io/docs/intl-messageformat) uses [ICU message syntax](https://unicode-org.github.io/icu/userguide/format_parse/messages/) and [CLDR locale data](http://cldr.unicode.org/).
For example, to support English and Spanish, create 2 JSON files:
**`src/intl/messages/en.json`**
```json
{
"greeting": "Hello, {name}!",
"welcome": "Welcome to our app!",
"todayIs": "Today is {ts, date, ::yyyyMMdd}"
}
```
**`src/intl/messages/es.json`**
```json
{
"greeting": "Hola, {name}!",
"welcome": "Bienvenido a nuestra aplicación!",
"todayIs": "Hoy es {ts, date, ::yyyyMMdd}"
}
```
## Step 2 | Create a function to load the messages JSON file
Create and export a helper function that loads the correct messages JSON based on the extension's language:
1. Create a file to host the helper function. For example, `src/intl/load-messages.js`.
1. Import `i18n` from `@wix/essentials`:
```js
import { i18n } from "@wix/essentials";
```
1. Create and export a function that calls [`i18n.getLanguage()`](https://dev.wix.com/docs/sdk/core-modules/essentials/i18n.md#getlanguage) and returns the correct messages JSON based on the language retrieved. \
For example:
```js
export async function loadMessages() {
switch (i18n.getLanguage()) {
case "es":
return (await import("./es.json")).default;
default:
return (await import("./en.json")).default;
}
}
```
At the end of this step, your file should look similar to this:
**`src/intl/load-messages.js`**
```js
import { i18n } from "@wix/essentials";
export async function loadMessages() {
switch (i18n.getLanguage()) {
case "es":
return (await import("./es.json")).default;
default:
return (await import("./en.json")).default;
}
}
```
## Step 3 | Initialize `intl`
This step is implemented differently depending on whether your app's extensions use React or plain JavaScript.
### React
Render your extensions using the `IntlProvider` component from the [`react-intl` package](https://formatjs.io/docs/react-intl/).
To avoid repeating this code for each of your apps' extension, create a higher order component (HOC) that you can use to wrap your extensions with `IntlProvider`:
1. Create a component called `withIntlProvider`. This is your HOC that will wrap your extensions with `IntlProvider`.
1. Create a state variable.
1. Using `useEffect()`, when the component loads, call `loadMessages()` that you defined in [Step 2](#step-2--create-a-function-to-load-the-messages-json-file), and then save the response in your state variable.
1. If `loadMessages()` doesn't return a value, the component should return `null`.
1. Return an [`IntlProvider` component](https://formatjs.io/docs/react-intl/components#intlprovider) with the following props:
- Pass the loaded messages to the `messages` prop.
- Pass the value of [`i18n.getLocale()`](https://dev.wix.com/docs/sdk/core-modules/essentials/i18n.md#getlanguage) to the `locale` prop.
- Set the default locale.
- Pass `