> For the complete documentation index, see [llms.txt](https://codedthemes.gitbook.io/materially-react-material-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codedthemes.gitbook.io/materially-react-material-documentation/localization.md).

# Localization

Materially supports four types of international languages ('**en**' - English, '**fr**' - French, '**ro**' - Romanian, '**zh**' - Chinese). You can switch language from the header bar. We internationalize the main menu for all four languages, When you change it from the header, you will see the effect there. If you want to configure one more language or set a default language then continue reading below\...

## IntlProvider

React Intl uses the provider pattern to scope an i18n context to a tree of components. This allows configurations like the current locale and set of translated strings/messages to be provided at the root of a component tree and made available to the `<FormattedMessage>` components.&#x20;

## locale, formats, and messages

&#x20;The user's current locale and what the app should be rendered in. While `defaultLocale` and `defaultFormats` are for fallbacks or during development and represent the app's default. Notice how there is no, `defaultMessages`that's because each [Message Descriptor](https://formatjs.io/docs/react-intl/components#message-descriptor) provides a `defaultMessage`

## How does it work?

Add node modules `react-intl` emo

```
yarn add react-intl / npm install --save react-intl
```

Data for locale files exist at **`src\utils\locales`**

```
{
  "dashboard": "Dashboard",
  "default": "Default",

  "widget": "Widget",
  "widgets": "Widgets",
  "statistic": "Statistic",
...
... 
}

```

Open the file `config` and set the language.

{% tabs %}
{% tab title="Typescript" %}
{% code title="src/config.ts" %}

```typescript
const config: ConfigProps = {
  mode: ThemeMode.LIGHT,
  i18n: ThemeI18n.EN,
  themeDirection: ThemeDirection.LTR
};
```

{% endcode %}
{% endtab %}

{% tab title="Javascript" %}
{% code title="src/config.js" %}

```javascript
const config = {
  mode: ThemeMode.LIGHT,
  i18n: ThemeI18n.EN,
  themeDirection: ThemeDirection.LTR
};
```

{% endcode %}
{% endtab %}
{% endtabs %}

Open file `Locales` and apply **IntlProvider**

{% tabs %}
{% tab title="Typescript" %}
{% code title="src/components/Locales.tsx" %}

```typescript
import { ReactElement, useEffect, useState } from 'react';

// third party
import { IntlProvider, MessageFormatElement } from 'react-intl';

// project imports
import { ThemeI18n } from 'config';
import useConfig from 'hooks/useConfig';
import { ChildrenProps } from 'types/root';

// locales
const loadLocaleData = (locale: ThemeI18n) => {
  switch (locale) {
    case ThemeI18n.FR:
      return import('utils/locales/fr.json');
    case ThemeI18n.RO:
      return import('utils/locales/ro.json');
    case ThemeI18n.ZH:
      return import('utils/locales/zh.json');
    case ThemeI18n.EN:
    default:
      return import('utils/locales/en.json');
  }
};

// ==============================|| LOCALIZATION ||============================== //

export default function Locales({ children }: ChildrenProps) {
  const { i18n } = useConfig();

  const [messages, setMessages] = useState<Record<string, string> | Record<string, MessageFormatElement[]> | undefined>();

  useEffect(() => {
    loadLocaleData(i18n).then((d: { default: Record<string, string> | Record<string, MessageFormatElement[]> | undefined }) => {
      setMessages(d.default);
    });
  }, [i18n]);

  return (
    <>
      {messages && (
        <IntlProvider locale={i18n} defaultLocale="en" messages={messages}>
          {children as ReactElement}
        </IntlProvider>
      )}
    </>
  );
}

```

{% endcode %}
{% endtab %}

{% tab title="Javascript" %}
{% code title="src/components/Locales.jsx" %}

```javascript
import PropTypes from 'prop-types';
import { useEffect, useState } from 'react';

// third party
import { IntlProvider } from 'react-intl';

// project imports
import { ThemeI18n } from 'config';
import useConfig from 'hooks/useConfig';

// locales
const loadLocaleData = (locale) => {
  switch (locale) {
    case ThemeI18n.FR:
      return import('utils/locales/fr.json');
    case ThemeI18n.RO:
      return import('utils/locales/ro.json');
    case ThemeI18n.ZH:
      return import('utils/locales/zh.json');
    case ThemeI18n.EN:
    default:
      return import('utils/locales/en.json');
  }
};

// ==============================|| LOCALIZATION ||============================== //

export default function Locales({ children }) {
  const { i18n } = useConfig();

  const [messages, setMessages] = useState();

  useEffect(() => {
    loadLocaleData(i18n).then((d) => {
      setMessages(d.default);
    });
  }, [i18n]);

  return (
    <>
      {messages && (
        <IntlProvider locale={i18n} defaultLocale="en" messages={messages}>
          {children}
        </IntlProvider>
      )}
    </>
  );
}

Locales.propTypes = { children: PropTypes.any };

```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://codedthemes.gitbook.io/materially-react-material-documentation/localization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
