Спросите свой вопрос и получите сводку документа, используя эту страницу и выбранного вами поставщика AI
Этот документ устарел, базовая версия была обновлена 23 августа 2025 г..
Перейти к английской документацииИстория версий
- "Инициализация истории"v5.5.1029.06.2025
Содержимое этой страницы было переведено с помощью ИИ.
Смотреть последнюю версию оригинального контента на английскомIf 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
Перевод
Определение переводов
With react-intlayer, you can use translations in React components. Here's an example:
Копировать код в буфер обмена
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.
Конфигурация локалей
Для обеспечения правильной обработки переводов вы можете настроить поддерживаемые локали в файле intlayer.config.ts. Эта конфигурация позволяет определить языки, которые поддерживает ваше приложение:
Копировать код в буфер обмена
import { Locales, type IntlayerConfig } from "intlayer";
const config: IntlayerConfig = {
internationalization: {
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
},
};
export default config;Использование переводов в React-компонентах
With react-intlayer, you can use translations in React components. Here's an example:
Копировать код в буфер обмена
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.
Пользовательские объекты контента
intlayer поддерживает пользовательские объекты контента для перевода, позволяя определять более сложные структуры при обеспечении типовой безопасности. Вот пример с пользовательским объектом:
Копировать код в буфер обмена
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;