Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Update Solid useIntlayer API usage to direct property access"v8.9.05/4/2026
- "Update compiler options, add FilePathPattern support"v8.2.03/9/2026
- "Initial release"v8.1.62/23/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
How to make multilingual (i18n) an existing Vite and React application afterward (i18n guide 2026)
See Application Template on GitHub.
Table of Contents
Why is it hard to internationalize an existing application?
If you've ever tried to add multiple languages to an app that was built for just one, you know the pain. It's not just "hard", it's tedious. You have to comb through every single file, hunt down every string of text, and move them into separate dictionary files.
Then comes the risky part: replacing all that text with code hooks without breaking your layout or logic. It's the kind of work that halts new feature development for weeks and feels like endless refactoring.
What is the Intlayer Compiler?
The Intlayer Compiler was built to skip that manual grunt work. Instead of you manually extracting strings, the compiler does it for you. It scans your code, finds the text, and uses AI to generate the dictionaries behind the scenes. Then, it modifies your code during the build to inject the necessary i18n hooks. Basically, you keep writing your app as if it's single-language, and the compiler handles the multilingual transformation automatically.
Doc Compiler: /en/doc/compiler
Limitations
Because the compiler performs code analysis and transformation (inserting hooks and generating dictionaries) at compile time, it can slow down the build process of your application.
To mitigate this impact during development, you can configure the compiler to run in 'build-only' mode or disable it when not needed.
Step-by-Step Guide to Set Up Intlayer in a Vite and React Application
Install Dependencies
Install the necessary packages using npm:
bashCopy codeCopy the code to the clipboard
the
--interactiveflag is optional. Useintlayer-cli initif you're an AI agent.This command will detect your environment and install the required packages. For example:
bashCopy codeCopy the code to the clipboard
intlayer The core package that provides internationalization tools for configuration management, translation, content declaration, transpilation, and CLI commands.
react-intlayer The package that integrates Intlayer with React application. It provides context providers and hooks for React internationalization.
vite-intlayer Includes the Vite plugin for integrating Intlayer with the Vite bundler, as well as middleware for detecting the user's preferred locale, managing cookies, and handling URL redirection.
Configure Your Project
Create a config file to configure the languages of your application:
intlayer.config.tsCopy codeCopy the code to the clipboard
Note: Ensure you have your
OPEN_AI_API_KEYset in your environment variables.Through this configuration file, you can set up localized URLs, middleware redirection, cookie names, the location and extension of your content declarations, disable Intlayer logs in the console, and more. For a complete list of available parameters, refer to the configuration documentation.
Integrate Intlayer in Your Vite Configuration
Add the intlayer plugin into your configuration.
vite.config.tsCopy codeCopy the code to the clipboard
The
intlayer()Vite plugin is used to integrate Intlayer with Vite. It ensures the building of content declaration files and monitors them in development mode. It defines Intlayer environment variables within the Vite application. Additionally, it provides aliases to optimize performance.The
intlayerCompiler()Vite plugin is used to extract content from component and write.contentfiles.Since Intlayer v9, the compiler is bundled directly into the
intlayer()plugin and activates automatically oncecompiler.enabledis set with acompiler.outputpath. RegisteringintlayerCompiler()separately as shown below is now optional — it deduplicates itself if also added. See the v9 release notes.Compile your code
Just write your components with hardcoded strings in your default locale. The compiler handles the rest.
Example of how your page might look:
src/App.tsxCopy codeCopy the code to the clipboard
i18n/app-content.content.jsonCopy codeCopy the code to the clipboard
src/App.tsxCopy codeCopy the code to the clipboard
IntlayerProvideris used to provide the locale to nested components.
Change the language of your content
OptionalTo change the language of your content, you can use the
setLocalefunction provided by theuseLocalehook. This function allows you to set the locale of the application and update the content accordingly.src/components/LocaleSwitcher.tsxCopy codeCopy the code to the clipboard
To Learn more about the
useLocalehook, refer to the documentation.Fill missing translation
OptionalIntlayer provide a CLI tool to help you fill missing translations. You can use the
intlayercommand to test and fill missing translations from your code.bashCopy codeCopy the code to the clipboard
bashCopy codeCopy the code to the clipboard
For more details, refer to the CLI documentation
(Optional) Sitemap and robots.txt (build-time)
Intlayer includes formatters such as generateSitemap and getMultilingualUrls that produce crawler-ready multilingual sitemap.xml and robots.txt output you can write into your project’s public/ folder. In practice you run a small Node script before Vite (for example predev / prebuild npm hooks) so those files exist when you build or serve the app.
Sitemap
Intlayer’s sitemap generator respects your locale setup and includes the usual metadata for crawlers.
The generated sitemap supports thexhtml:linknamespace (hreflang XML extensions). Unlike basic generators that only emit flat URLs, Intlayer wires bidirectional links between every localized variant of each page (for example/about,/fr/about, or/about?lang=fr, depending on your routing mode), which helps search engines relate localized URLs.
Robots.txt
Use getMultilingualUrls so Disallow entries cover every localized spelling of sensitive paths.
1. Add generate-seo.mjs at the project root
Copy the code to the clipboard
intlayer must be installed so the script can import it. Set SITE_URL in the environment for production (for example in CI).
Prefergenerate-seo.mjsfor Node ESM. If you usegenerate-seo.jsinstead, ensure"type": "module"is set inpackage.json, or run Node with ESM enabled.
2. Run the script before Vite
Copy the code to the clipboard
Adjust if you use pnpm or yarn. You can also invoke the same script from CI or another step if that fits your workflow.
Git Configuration
It is recommended to ignore the files generated by Intlayer. This allows you to avoid committing them to your Git repository.
To do this, you can add the following instructions to your .gitignore file:
Copy the code to the clipboard
VS Code Extension
To improve your development experience with Intlayer, you can install the official Intlayer VS Code Extension.
Install from the VS Code Marketplace
This extension provides:
- Autocompletion for translation keys.
- Real-time error detection for missing translations.
- Inline previews of translated content.
- Quick actions to easily create and update translations.
For more details on how to use the extension, refer to the Intlayer VS Code Extension documentation.
Go Further
To go further, you can implement the visual editor or externalize your content using the CMS.
Frequently Asked Questions
react-i18next/i18next: JSON namespaces loaded at runtime, with keys written by hand at every call site.react-intlandLingui: ICU messages with an extraction step you run yourself.Intlayer: content compiled out of your components at build time, fully typed, with AI translation, a visual editor and a CMS.
This guide uses the compiler setup, where you keep writing plain strings in your components and the dictionaries are generated for you. See why Intlayer and the benchmark.
Much less than a namespace based setup, because a page never downloads a catalog it does not render. The build time compiler replaces useIntlayer calls with the exact dictionary entries a component uses, so unused keys and unused languages are dropped, and dynamic dictionaries split the rest per locale. Measured against the usual alternatives, Intlayer reduces bundle and page size by up to 50%. See bundle optimization and the benchmark.
Yes, and there are two paths. You can migrate the content progressively with the react-i18next migration guide or the i18next migration guide. Or you can keep your current API entirely: the compat adapters expose the exact same API as react-i18next, react-intl and i18next, but served by Intlayer dictionaries, so imports change and component code does not.
Yes. The sync JSON plugin keeps your /messages/{locale}/{namespace}.json files as the source of truth and generates Intlayer dictionaries from them, in both directions. A sync PO plugin does the same for gettext catalogs, and per locale files let you split content by language instead of grouping locales in one file.
No, and that is what this guide sets up. You write your components with plain strings in your default locale, and the Intlayer Compiler scans the source on every build, extracts the user facing text and generates the dictionaries, so there are no keys to create or maintain by hand.
Two limits are worth knowing. The compiler works by static analysis, so strings that only exist at runtime, such as API error codes or CMS fields, stay out of reach and still need a declared dictionary. And it has to tell user facing text apart from application logic like className="active" or a status code, which needs a few annotations in a large codebase.
If you would rather keep control, npx intlayer extract does the same extraction once, on the files you choose, and writes a .content file next to each component for you to review. See the extract command.
Five pieces, all optional:
- VS Code extension: jump from a
useIntlayerkey to the content file that declares it, extract content from a component, and run build, fill, test, push and pull from the command palette or a dedicated Intlayer tab. - LSP server: the same awareness in any editor that speaks LSP, with go to definition, find all references, hover previews of a translated value, autocompletion of keys and fields, and a warning when a key is not declared anywhere. It also resolves
i18next,react-i18next,next-intlanduse-intlcalls, which helps while you migrate. - MCP server: exposes the Intlayer documentation and CLI to Cursor, VS Code, Claude Desktop, Claude Code and ChatGPT, so an assistant answers from current docs instead of guessing, and can run commands such as
intlayer fillitself. - Agent skills: focused skills such as
intlayer-config,intlayer-cliandintlayer-content, plus one per framework, that teach an agent your routing setup and the content node types. - ESLint plugin:
no-raw-textflags hardcoded strings, with further rules for static dictionary keys and unused content.
