Đặt câu hỏi và nhận tóm tắt tài liệu bằng cách tham chiếu trang này và nhà cung cấp AI bạn chọn
Lịch sử phiên bản
- "Init history"v9.0.013/6/2026
Nội dung của trang này đã được dịch bằng AI.
Xem phiên bản mới nhất của nội dung gốc bằng tiếng AnhIf 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
Migrate from React Intl to Intlayer
If your React application uses react-intl (FormatJS), transitioning to Intlayer is a breeze. Our compat layer seamlessly handles ICU MessageFormat and all existing Formatted* components.
What to do
Start by running the initialization command in your project:
Sao chép mã vào clipboard
npx intlayer initThen, set up the Intlayer Vite or Next.js plugin in your configuration. This plugin injects build-time aliases to redirect react-intl imports to @intlayer/react-intl.
Sao chép mã vào clipboard
import { defineConfig } from "vite";import react from "@vitejs/plugin-react";import reactIntlVitePlugin from "@intlayer/react-intl/plugin";export default defineConfig({ plugins: [react(), reactIntlVitePlugin()],});What it does under the hood
The bundler plugin aliases react-intl to @intlayer/react-intl. Instead of parsing large JSON files manually and wrapping your app in an IntlProvider, the Intlayer plugin statically extracts keys and uses Intlayer dictionaries at runtime.
Under the hood:
- ICU MessageFormat: Intlayer uses the
resolveMessage(..., 'icu')resolver which fully supports the ICU pluralization, selection, date/number formatting, and rich text tags natively. - Method & JSX callers:
intl.formatMessage({ id: 'a.b' })and<FormattedMessage id="a.b">are identified by the Intlayer compiler plugins (@intlayer/babel/@intlayer/swc), converting flat dotted keys so that the first segment correctly resolves to the Intlayer dictionary key. - Formatters:
<FormattedNumber>,<FormattedDate>, etc., bridge over to the nativecore/formattersusingIntl.