Author:
    Creation:2026-11-23Last update:2026-11-23

    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

    1. Compat adapter (recommended for existing apps): Install @intlayer/react-intl. It exposes the same API as react-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.
    2. Full migration: Gradually replace react-intl calls with useIntlayer and .content.ts files co-located with your components.

    Table of Contents

    Quick migration

    1. Install Dependencies

      bash
      npx intlayer init --interactive
      
      The --interactive flag is optional. Use intlayer-cli init if you're an AI agent.

      The command detects your environment and installs the required packages, for example:

      bash
      npm install intlayer react-intlayer @intlayer/react-intl @intlayer/sync-json-plugin
      
      Keep react-intl installed: it provides the TypeScript types.
    2. Configure Intlayer

      Point the syncJSON plugin at your existing message files. react-intl catalogues are flat maps of dotted ids:

      src/lang/en.json
      {
        "home.title": "Welcome",
        "home.greeting": "Hello {name}",
        "cart.items": "{count, plural, one {# item} other {# items}}"
      }
      
      intlayer.config.ts
      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.
    3. Add the Vite plugin

      reactIntlVitePlugin() runs the Intlayer build and aliases react-intl to @intlayer/react-intl, so no source file changes are needed.

      vite.config.ts
      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 example withIntlayer from next-intlayer for Next.js.
    4. Stop passing messages to IntlProvider

      IntlProvider keeps working, but messages are now loaded by Intlayer. Remove the messages prop and the catalogue import:

      src/main.tsx
      import { IntlProvider } from "react-intl";
      
      export const App = ({ locale }: { locale: string }) => (
        <IntlProvider locale={locale} defaultLocale="en">
          <Home />
        </IntlProvider>
      );
      
      If messages is still passed, it is ignored and a warning is printed in development.

    Your components keep working unchanged, with typed ids:

    src/Home.tsx
    import { FormattedMessage, FormattedNumber, useIntl } from "react-intl";
    
    export const Home = () => {
      const intl = useIntl();
    
      return (
        <main>
          <h1>{intl.formatMessage({ id: "home.title" })}</h1>
          <FormattedMessage id="home.greeting" values={{ name: "Ada" }} />
          <FormattedNumber value={42} style="currency" currency="EUR" />
        </main>
      );
    };
    

    Complete migration

    1. Explicit import renaming (optional)

      Optional

      The Vite plugin already handles aliasing. To make the dependency explicit:

      BeforeAfter
      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'
    2. Move content to .content.ts files

      Optional

      New components can use native Intlayer content, side by side with existing react-intl calls:

      src/home.content.ts
      import { t, type Dictionary } from "intlayer";
      
      const homeContent = {
        key: "home",
        content: {
          title: t({ en: "Welcome", fr: "Bienvenue", es: "Bienvenido" }),
        },
      } satisfies Dictionary;
      
      export default homeContent;
      
      src/Home.tsx
      import { useIntlayer } from "react-intlayer";
      
      export const Home = () => {
        const { title } = useIntlayer("home");
      
        return <h1>{title}</h1>;
      };
      
    3. Enable AI-powered translation

      Optional
      bash
      # Test for missing translations (add to CI)
      npx intlayer test
      
      # Fill missing translations with AI
      npx intlayer fill
      

      Filled translations are written back to your JSON files. See the CLI documentation for AI configuration.

    What you can delete after migration

    File / patternWhy it's no longer needed
    messages prop and catalogue loadingDictionaries are compiled and loaded by Intlayer.
    formatjs compile stepIntlayer parses ICU messages from the JSON files directly.
    babel-plugin-formatjs id generationUse explicit dotted ids so each id maps to a dictionary.

    Configure TypeScript

    Include the generated types in your tsconfig.json:

    tsconfig.json
    {
      "include": [
        // ... your existing paths
        ".intlayer/**/*.ts",
      ],
    }
    

    Git Configuration

    .gitignore
    # Ignore the files generated by Intlayer
    .intlayer
    

    Go Further