Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
This doc is out of date, the base version has been updated on 23 August 2025.
Go to English docVersion History
- "Init history"v5.5.1029/06/2025
The content of this page was translated using an AI.
See the last version of the original content in EnglishIf you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy doc Markdown to clipboard
Translation
Defining Translations
With react-intlayer, you can use translations in React components. Here's an example:
Copy the code to the clipboard
import type { FC } from "react";
import { useIntlayer } from "react-intlayer";
const MyComponent: FC = () => {
const content = useIntlayer("multi_lang");
return (
<div>
<p>{content.welcomeMessage}</p>
</div>
);
};
export default MyComponent;This component fetches the corresponding translation based on the current locale set in your application.
Configuration for Locales
To ensure proper translation handling, you can configure the accepted locales in intlayer.config.ts. This configuration allows you to define the languages that your application supports:
Copy the code to the clipboard
import { Locales, type IntlayerConfig } from "intlayer";
const config: IntlayerConfig = {
internationalization: {
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
},
};
export default config;Using Translations in React Components
With react-intlayer, you can use translations in React components. Here's an example:
Copy the code to the clipboard
import type { FC } from "react";
import { useIntlayer } from "react-intlayer";
const MyComponent: FC = () => {
const content = useIntlayer("multi_lang");
return (
<div>
<p>{content.welcomeMessage}</p>
</div>
);
};
export default MyComponent;This component fetches the corresponding translation based on the current locale set in your application.
Custom Content Objects
intlayer supports custom content objects for translation, allowing you to define more complex structures while ensuring type safety. Here's an example with a custom object:
Copy the code to the clipboard
import { t, type Dictionary } from "intlayer";
interface ICustomContent {
title: string;
content: string;
}
const customContent = {
key: "custom_content",
content: {
profileText: t<ICustomContent>({
en: {
title: "Page Title",
content: "Page Content",
},
fr: {
title: "Titre de la Page",
content: "Contenu de la Page",
},
es: {
title: "Título de la Página",
content: "Contenido de la Página",
},
}),
},
} satisfies Dictionary;
export default customContent;