Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Init history"v9.8.523/11/2026
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
Migrating from react-intl (FormatJS) to Intlayer
Why migrate from react-intl to Intlayer?
With react-intl, every message of the locale is passed to IntlProvider, so each page carries the whole catalogue. Intlayer only ships the dictionaries each page uses, which reduces your bundle and page sizes by up to 50%.
Message ids are typed against your dictionaries: invalid ids fail at build time. Content can be co-located with the components that use it.
Co-located content reduces the context needed by LLMs. Intlayer ships a CLI to test for missing translations, an LSP, an MCP server and agent skills.
Translate missing messages in your CI/CD pipeline with the LLM of your choice, or in the background with the web platform.
Intlayer provides a self-hosted visual editor and a full CMS so translators and copywriters can edit content in real time.
To understand where these libraries come from, read the history of JavaScript i18n.
Migration strategies
- Compat adapter (recommended for existing apps): Install
@intlayer/react-intl. It exposes the same API asreact-intl(IntlProvider,useIntl,FormattedMessage,FormattedNumber,FormattedDate,defineMessages,createIntl…) and serves messages from Intlayer dictionaries. ICU MessageFormat, plurals, selects and rich text tags work as before. - Full migration: Gradually replace react-intl calls with
useIntlayerand.content.tsfiles co-located with your components.
Table of Contents
Quick migration
Install Dependencies
bashCopy codeCopy the code to the clipboard
The
--interactiveflag is optional. Useintlayer-cli initif you're an AI agent.The command detects your environment and installs the required packages, for example:
bashCopy codeCopy the code to the clipboard
Keep
react-intlinstalled: it provides the TypeScript types.Configure Intlayer
Point the
syncJSONplugin at your existing message files. react-intl catalogues are flat maps of dotted ids:src/lang/en.jsonCopy codeCopy the code to the clipboard
intlayer.config.tsCopy codeCopy the code to the clipboard
import { Locales, type IntlayerConfig } from "intlayer"; import { syncJSON } from "@intlayer/sync-json-plugin"; const config: IntlayerConfig = { internationalization: { locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH], defaultLocale: Locales.ENGLISH, }, plugins: [ syncJSON({ // react-intl uses ICU MessageFormat format: "icu", source: ({ locale }) => `./src/lang/${locale}.json`, // 'home.title' → dictionary `home`, key `title` splitKeys: "key-prefix", }), ], }; export default config;The first segment of each id (
home) becomes an Intlayer dictionary, so each page only loads the dictionaries it uses. When Intlayer writes translations back, the file keeps its flat shape.Add the Vite plugin
reactIntlVitePlugin()runs the Intlayer build and aliasesreact-intlto@intlayer/react-intl, so no source file changes are needed.vite.config.tsCopy codeCopy the code to the clipboard
import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import { reactIntlVitePlugin } from "@intlayer/react-intl/plugin"; export default defineConfig({ plugins: [react(), reactIntlVitePlugin()], });Using another bundler? Rename the imports to
@intlayer/react-intl(see Step 5) and use the Intlayer plugin for your bundler, for examplewithIntlayerfromnext-intlayerfor Next.js.Stop passing messages to IntlProvider
IntlProviderkeeps working, but messages are now loaded by Intlayer. Remove themessagesprop and the catalogue import:src/main.tsxCopy codeCopy the code to the clipboard
If
messagesis still passed, it is ignored and a warning is printed in development.
Your components keep working unchanged, with typed ids:
Copy the code to the clipboard
Complete migration
Explicit import renaming (optional)
OptionalThe Vite plugin already handles aliasing. To make the dependency explicit:
Show all table contentOpen the table in a modal to view all data content clearly
Before After import { IntlProvider } from 'react-intl'import { IntlProvider } from '@intlayer/react-intl'import { useIntl } from 'react-intl'import { useIntl } from '@intlayer/react-intl'import { FormattedMessage } from 'react-intl'import { FormattedMessage } from '@intlayer/react-intl'import { defineMessages } from 'react-intl'import { defineMessages } from '@intlayer/react-intl'import { createIntl } from 'react-intl'import { createIntl } from '@intlayer/react-intl'Move content to .content.ts files
OptionalNew components can use native Intlayer content, side by side with existing react-intl calls:
src/home.content.tsCopy codeCopy the code to the clipboard
src/Home.tsxCopy codeCopy the code to the clipboard
Enable AI-powered translation
OptionalbashCopy codeCopy the code to the clipboard
Filled translations are written back to your JSON files. See the CLI documentation for AI configuration.
What you can delete after migration
Open the table in a modal to view all data content clearly
| File / pattern | Why it's no longer needed |
|---|---|
messages prop and catalogue loading | Dictionaries are compiled and loaded by Intlayer. |
formatjs compile step | Intlayer parses ICU messages from the JSON files directly. |
babel-plugin-formatjs id generation | Use explicit dotted ids so each id maps to a dictionary. |
Configure TypeScript
Include the generated types in your tsconfig.json:
Copy the code to the clipboard
Git Configuration
Copy the code to the clipboard
