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

    Migrating from Lingui to Intlayer

    Why migrate from Lingui to Intlayer?

    Lingui loads one compiled catalog per locale, holding every message of the app. Intlayer splits content per dictionary and only ships what each page uses, which reduces your bundle and page sizes by up to 50%.

    Intlayer dictionaries are fully typed, and can be co-located with the components that use them. No extract / compile step to remember: dictionaries are built by the bundler plugin.

    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/lingui. It exposes the same API as @lingui/core and @lingui/react (i18n, setupI18n, I18nProvider, useLingui, Trans) and serves messages from Intlayer dictionaries. Your macros ( t`…` , <Trans>, msg, plural) keep compiling exactly as before.
    2. Full migration: Gradually replace Lingui 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/lingui @intlayer/sync-po-plugin
      
      Keep @lingui/core, @lingui/react and your macro plugin (@lingui/babel-plugin-lingui-macro or @lingui/swc-plugin) installed. The macros still run, and the Lingui packages provide the TypeScript types.
    2. Configure Intlayer

      Intlayer reads your Lingui catalogs as the source of truth. With Lingui's default layout (src/locales/{locale}/messages.po), point the syncPO plugin at them:

      intlayer.config.ts
      import { Locales, type IntlayerConfig } from "intlayer";
      import { syncPO } from "@intlayer/sync-po-plugin";
      
      const config: IntlayerConfig = {
        internationalization: {
          locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
          defaultLocale: Locales.ENGLISH,
        },
        plugins: [
          syncPO({
            // ./src/locales/en/messages.po → dictionary `messages`
            source: ({ key, locale }) => `./src/locales/${locale}/${key}.po`,
          }),
        ],
      };
      
      export default config;
      

      With @lingui/format-json, use syncJSON with the ICU format:

      intlayer.config.ts
      import { syncJSON } from "@intlayer/sync-json-plugin";
      
      // ...
      plugins: [
        syncJSON({
          format: "icu",
          source: ({ key, locale }) => `./src/locales/${locale}/${key}.json`,
        }),
      ],
      
      Use explicit message ids (t({ id: "hero.title", message: "Welcome" }) or <Trans id="hero.title">). Ids generated from the source text are not resolved against the catalogs.
    3. Replace the Lingui Vite plugin

      Swap @lingui/vite-plugin for @intlayer/lingui/plugin. The binding stays lingui(): it runs the Intlayer build and aliases @lingui/core and @lingui/react to @intlayer/lingui, so no source file changes are needed.

      vite.config.ts
      import { defineConfig } from "vite";
      import react from "@vitejs/plugin-react";
      import { lingui } from "@intlayer/lingui/plugin"; // was "@lingui/vite-plugin"
      
      export default defineConfig({
        plugins: [
          react({
            babel: { plugins: ["@lingui/babel-plugin-lingui-macro"] },
          }),
          lingui(),
        ],
      });
      
      Keep the macro plugin in the React plugin (Babel or @lingui/swc-plugin), so macros are compiled to i18n._() calls before Intlayer resolves them.

    Your components keep working unchanged:

    src/Hero.tsx
    import { Trans, useLingui } from "@lingui/react/macro";
    
    export const Hero = ({ name }: { name: string }) => {
      const { t } = useLingui();
    
      return (
        <header>
          <h1>{t({ id: "hero.title", message: "Welcome" })}</h1>
          <Trans id="hero.greeting">Hello {name}</Trans>
        </header>
      );
    };
    

    Switching locale still goes through i18n.activate(locale), which updates every useLingui() consumer.

    Complete migration

    1. Remove runtime catalog loading

      Optional

      Messages now come from Intlayer dictionaries compiled at build time. Calls to i18n.load() / i18n.loadAndActivate() only serve as a fallback and print a warning in development. Replace them with i18n.activate(locale) and drop the lingui compile step. Keep lingui extract to collect new message ids.

    2. Explicit import renaming (optional)

      Optional

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

      BeforeAfter
      import { i18n } from '@lingui/core'import { i18n } from '@intlayer/lingui'
      import { setupI18n } from '@lingui/core'import { setupI18n } from '@intlayer/lingui'
      import { I18nProvider } from '@lingui/react'import { I18nProvider } from '@intlayer/lingui'
      import { useLingui, Trans } from '@lingui/react'import { useLingui, Trans } from '@intlayer/lingui'
    3. Move content to .content.ts files

      Optional

      New components can use native Intlayer content, side by side with existing Lingui calls:

      src/hero.content.ts
      import { t, type Dictionary } from "intlayer";
      
      const heroContent = {
        key: "hero",
        content: {
          title: t({ en: "Welcome", fr: "Bienvenue", es: "Bienvenido" }),
        },
      } satisfies Dictionary;
      
      export default heroContent;
      
      src/Hero.tsx
      import { useIntlayer } from "react-intlayer";
      
      export const Hero = () => {
        const { title } = useIntlayer("hero");
      
        return <h1>{title}</h1>;
      };
      
    4. 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 Lingui catalogs. See the CLI documentation for AI configuration.

    What you can delete after migration

    File / patternWhy it's no longer needed
    i18n.load() / dynamic catalog importsDictionaries are compiled and loaded by Intlayer.
    lingui compile and compiled .js catalogsIntlayer builds dictionaries from your catalogs directly.
    @lingui/vite-pluginReplaced by lingui() from @intlayer/lingui/plugin.

    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