HomeSandboxShowcaseAppDocBlog
    • EnglishEnglish
      EN
    • русскийRussian
      RU
    • 日本語Japanese
      JA
    • françaisFrench
      FR
    • 한국어Korean
      KO
    • 中文Chinese
      ZH
    • españolSpanish
      ES
    • DeutschGerman
      DE
    • العربيةArabic
      AR
    • italianoItalian
      IT
    • British EnglishBritish English
      EN-GB
    • portuguêsPortuguese
      PT
    • हिन्दीHindi
      HI
    • TürkçeTurkish
      TR
    • polskiPolish
      PL
    • IndonesiaIndonesian
      ID
    • Tiếng ViệtVietnamese
      VI
    • українськаUkrainian
      UK
    /
    Filter docs by framework
    Alt+←
    Why Intlayer ?
    Get Started
    Concept
    • How Intlayer Works
    • Configuration
    • TestFillBuildWatchExtractLoginPushPullConfigurationListVersionEditorLiveDebugDoc ReviewDoc TranslateSDK
    • Visual Editor
    • CMS
    • CI/CD Integration
    • TranslationPluralEnumerationConditionGenderInsertionFileNestingMarkdownHTMLFunction Fetching
    • Per Locale File
    • Compiler
    • Auto Fill
    • Testing
    • Bundle Optimization
    Environment
    • Next.js 14 and App Router
      Next.js 15
      Next.js no locale path
      Next.js and Page Router
      Compiler
    • Tanstack Start Solid
    • Astro and React
      Astro and Svelte
      Astro and Vue
      Astro and Solid
      Astro and Preact
      Astro and Lit
      Astro and Vanilla JS
    • React Router v7
      React Router v7 (fs-routes)
      Compiler
    • Nuxt and Vue
    • Vite and Solid
    • SvelteKit
    • Vite and Preact
    • Vite and Vanilla JS
    • Vite and Lit
    • Angular 19 (Webpack)
      Analog
    • React CRA
    • React Native and Expo
    • Express.js
      NestJS
      Fastify
      Hono
      Adonis
    • Lynx and React
    Plugins
    • JSON
    • gettext (.po)
    VS Code Extension
    Agent
    • MCP Server
    • Agent skills
    Releases
    • v8
    • v7
    • v6
    Benchmark
    • Next.js
    • TanStack
    • Vue
    • Solid
    • Svelte
    Blog
    Ask a question
    1. Documentation
    2. Compiler
    Creation:2025-09-09Last update:2026-03-12
    Reference this doc to your favorite AI assistant
    ChatGPT
    Claude
    DeepSeek
    Google AI mode
    Gemini
    Perplexity
    Mistral
    Grok

    Ask your question and get a summary of the document by referencing this page and the AI provider of your choice

    Version History

    1. "Update compiler options, add FilePathPattern support"
      v8.2.03/9/2026
    2. "Update compiler options"
      v8.1.72/25/2026
    3. "Release Compiler"
      v7.3.111/27/2025
    Edit this doc

    If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.

    GitHub link to the documentation
    Copy

    Copy doc Markdown to clipboard

    Intlayer Compiler | Automated Content Extraction for i18n

    What is the Intlayer Compiler?

    The Intlayer Compiler is a powerful tool designed to automate the process of internationalization (i18n) in your applications. It scans your source code (JSX, TSX, Vue, Svelte) for content declarations, extracts them, and automatically generates the necessary dictionary files. This allows you to keep your content co-located with your components while Intlayer handles the management and synchronization of your dictionaries.

    Why Use the Intlayer Compiler?

    • Automation: Eliminates manual copy-pasting of content into dictionaries.

    • Speed: Optimized content extraction ensuring your build process remains fast.

    • Developer Experience: Keep content declarations right where they are used, improving maintainability.

    • Live Updates: Supports Hot Module Replacement (HMR) for instant feedback during development.

    See the Compiler vs. Declarative i18n blog post for a deeper comparison.

    Why not use the Intlayer Compiler?

    While the compiler offers an excellent "just works" experience, it also introduces some trade-offs you should be aware of:

    • Heuristic ambiguity: The compiler must guess what is user-facing content vs. application logic (e.g., className="active", status codes, product IDs). In complex codebases, this can lead to false positives or missed strings that require manual annotations and exceptions.

    • Static-only extraction: Compiler-based extraction relies on static analysis. Strings that only exist at runtime (API error codes, CMS fields, etc.) cannot be discovered or translated by the compiler alone, so you still need a complementary runtime i18n strategy.

    For a deeper architectural comparison, see the blog post Compiler vs. Declarative i18n.

    As an alternative, to automate your i18n process while keeping full control of your content, Intlayer also provides an auto-extraction command intlayer extract (see CLI documentation), or the Intlayer: extract content to Dictionary command from the Intlayer VS Code extension (see VS Code extension documentation).

    Usage

    Vite

    For Vite-based applications (React, Vue, Svelte, etc.), the easiest way to use the compiler is through the vite-intlayer plugin.

    Installation

    bash
    Copy code

    Copy the code to the clipboard

    npm install vite-intlayer

    Configuration

    Update your vite.config.ts to include the intlayerCompiler plugin:

    vite.config.ts
    Copy code

    Copy the code to the clipboard

    import { defineConfig } from "vite";import { intlayer, intlayerCompiler } from "vite-intlayer";export default defineConfig({ plugins: [   intlayer(),   intlayerCompiler(), // Adds the compiler plugin ],});

    See complete tutorial: Intlayer Compiler with Vite+React

    Framework Support

    The Vite plugin automatically detects and handles different file types:

    • React / JSX / TSX: Handled natively.

    • Vue: Requires @intlayer/vue-compiler.

    • Svelte: Requires @intlayer/svelte-compiler.

    Make sure to install the appropriate compiler package for your framework:

    bash
    Copy code

    Copy the code to the clipboard

    # For Vuenpm install @intlayer/vue-compiler# For Sveltenpm install @intlayer/svelte-compiler

    Next.js (Babel)

    For Next.js or other Webpack-based applications using Babel, you can configure the compiler using the @intlayer/babel plugin.

    Installation

    bash
    Copy code

    Copy the code to the clipboard

    npm install @intlayer/babel

    Configuration

    Update your babel.config.js (or babel.config.json) to include the extraction plugin. We provide a helper getExtractPluginOptions to load your Intlayer configuration automatically.

    babel.config.js
    Copy code

    Copy the code to the clipboard

    const { intlayerExtractBabelPlugin, intlayerOptimizeBabelPlugin, getExtractPluginOptions, getOptimizePluginOptions,} = require("@intlayer/babel");module.exports = { presets: ["next/babel"], plugins: [   // Extract content from components into dictionaries   [intlayerExtractBabelPlugin, getExtractPluginOptions()],   // Optimize imports by replacing useIntlayer with direct dictionary imports   [intlayerOptimizeBabelPlugin, getOptimizePluginOptions()], ],};

    This configuration ensures that content declared in your components is automatically extracted and used to generate dictionaries during your build process.

    See complete tutorial: Intlayer Compiler with Next.js

    Custom config

    To customize the compiler behavior, you can update the intlayer.config.ts file in the root of your project.

    intlayer.config.ts
    Copy code

    Copy the code to the clipboard

    import { type IntlayerConfig, Locales } from "intlayer";const config: IntlayerConfig = {  compiler: {    /**     * Indicates if the compiler should be enabled.     * Set to 'build-only' to skip the compiler during development and speed up start times.     */    enabled: true,    /**     * Defines the output files path. Replaces `outputDir`.     *     * - `./` paths are resolved relative to the component directory.     * - `/` paths are resolved relative to the project root (`baseDir`).     *     * - Including the `{{locale}}` variable in the path will trigger the generation of separate dictionaries per locale.     *     * Example:     * ```ts     * {     *   // Create Multilingual .content.ts files close to the component     *   output: ({ fileName, extension }) => `./${fileName}${extension}`,     *     *   // output: './{{fileName}}{{extension}}', // Equivalent using template string     * }     * ```     *     * ```ts     * {     *   // Create centralize per-locale JSON at the root of the project     *   output: ({ key, locale }) => `/locales/${locale}/${key}.content.json`,     *     *   // output: '/locales/{{locale}}/{{key}}.content.json', // Equivalent using template string     * }     * ```     *     * Variable list:     *   - `fileName`: The name of the file.     *   - `key`: The key of the content.     *   - `locale`: The locale of the content.     *   - `extension`: The extension of the file.     *   - `componentFileName`: The name of the component file.     *   - `componentExtension`: The extension of the component file.     *   - `format`: The format of the dictionary.     *   - `componentFormat`: The format of the component dictionary.     *   - `componentDirPath`: The directory path of the component.     */    output: ({ fileName, extension }) => `./${fileName}${extension}`,    /**     * Indicates if the components should be saved after being transformed.     *     * - If `true`, the compiler will rewrite the component file in the disk. So the transformation will be permanent, and the compiler will skip the transformation for the next process. That way, the compiler can transform the app, and then it can be removed.     *     * - If `false`, the compiler will inject the `useIntlayer()` function call into the code in the build output only, and keep the base codebase intact. The transformation will be done only in memory.     */    saveComponents: false,    /**     * Inset only content into the generated file. Useful for per-locale i18next or ICU MessageFormat JSON outputs.     *     * - `output: ({ locale, key }) => `./locale/${locale}/${key}.json`,`     */    noMetadata: false,    /**     * Dictionary key prefix     */    dictionaryKeyPrefix: "", // Add an optional prefix for the extracted dictionary keys  },};export default config;

    Compiler Configuration Reference

    The following properties can be configured in the compiler block of your intlayer.config.ts file:

    • enabled:

      • Type: boolean | 'build-only'
      • Default: true
      • Description: Indicates if the compiler should be enabled.
    • dictionaryKeyPrefix:

      • Type: string
      • Default: ''
      • Description: Prefix for the extracted dictionary keys.
    • transformPattern:

      • Type: string | string[]
      • Default: ['**/*.{js,ts,mjs,cjs,jsx,tsx,vue,svelte}', '!**/node_modules/**']
      • Description: (Deprecated: use build.traversePattern instead) Patterns to traverse the code to optimize.
    • excludePattern:

      • Type: string | string[]
      • Default: ['**/node_modules/**']
      • Description: (Deprecated: use build.traversePattern instead) Patterns to exclude from the optimization.
    • output:

      • Type: FilePathPattern
      • Default: ({ key }) => 'compiler/${key}.content.json'
      • Description: Defines the output files path. Replaces outputDir. Handles dynamic variables like {{locale}}, {{key}}, {{fileName}}, {{extension}}, {{format}}, {{dirPath}}, {{componentFileName}}, {{componentExtension}}, {{componentFormat}}. Can be set as a string using 'my/{{var}}/path' format, or as a function.
      • Note: ./**/* Path are resolved relatively to the component. /**/* path are resolved relatively to the Intlayer baseDir.
      • Note: If locale is set in the path, it will generate per-locale dictionaries.
      • Example: output: ({ locale, key }) => 'compiler/${locale}/${key}.json'
    • noMetadata:

      • Type: boolean
      • Default: false
      • Description: Indicates if the metadata should be saved in the file. If true, the compiler will not save the metadata of the dictionaries (key, content wrapper). Useful for per-locale i18next or ICU MessageFormat JSON outputs.
      • Note: Useful if used with loadJSON plugin.
      • Example: If true: json { "key": "value" } If false: json { "key": "value", "content": { "key": "value" } }
    • saveComponents:

      • Type: boolean
      • Default: false
      • Description: Indicates if the components should be saved after being transformed.
        • If true, the compiler will rewrite the component file in the disk. The transformation will be permanent, and the compiler can then be removed.
        • If false, the compiler will inject the useIntlayer() function call into the code in the build output only, and keep the base codebase intact. The transformation will be done only in memory.

    Fill missing translation

    Intlayer provide a CLI tool to help you fill missing translations. You can use the intlayer command to test and fill missing translations from your code.

    bash
    Copy code

    Copy the code to the clipboard

    npx intlayer test         # Test if there is missing translations
    bash
    Copy code

    Copy the code to the clipboard

    npx intlayer fill         # Fill missing translations

    Extract

    Intlayer provide a CLI tool to extract content from your code. You can use the intlayer extract command to extract content from your code.

    bash
    Copy code

    Copy the code to the clipboard

    npx intlayer extract
    For more details, refer to the CLI documentation
    Per Locale File
    Auto Fill
    Alt+→

    In this page

      Discussions are anonymous and regularly reviewed to address common issues. Feel free to share feature ideas, feedback on the documentation, or anything related to Intlayer, we use this input to shape our roadmap and improve the product.

      npm install vite-intlayer
      import { defineConfig } from "vite";import { intlayer, intlayerCompiler } from "vite-intlayer";export default defineConfig({ plugins: [   intlayer(),   intlayerCompiler(), // Adds the compiler plugin ],});
      # For Vuenpm install @intlayer/vue-compiler# For Sveltenpm install @intlayer/svelte-compiler
      npm install @intlayer/babel
      const { intlayerExtractBabelPlugin, intlayerOptimizeBabelPlugin, getExtractPluginOptions, getOptimizePluginOptions,} = require("@intlayer/babel");module.exports = { presets: ["next/babel"], plugins: [   // Extract content from components into dictionaries   [intlayerExtractBabelPlugin, getExtractPluginOptions()],   // Optimize imports by replacing useIntlayer with direct dictionary imports   [intlayerOptimizeBabelPlugin, getOptimizePluginOptions()], ],};
      import { type IntlayerConfig, Locales } from "intlayer";const config: IntlayerConfig = {  compiler: {    /**     * Indicates if the compiler should be enabled.     * Set to 'build-only' to skip the compiler during development and speed up start times.     */    enabled: true,    /**     * Defines the output files path. Replaces `outputDir`.     *     * - `./` paths are resolved relative to the component directory.     * - `/` paths are resolved relative to the project root (`baseDir`).     *     * - Including the `{{locale}}` variable in the path will trigger the generation of separate dictionaries per locale.     *     * Example:     * ```ts     * {     *   // Create Multilingual .content.ts files close to the component     *   output: ({ fileName, extension }) => `./${fileName}${extension}`,     *     *   // output: './{{fileName}}{{extension}}', // Equivalent using template string     * }     * ```     *     * ```ts     * {     *   // Create centralize per-locale JSON at the root of the project     *   output: ({ key, locale }) => `/locales/${locale}/${key}.content.json`,     *     *   // output: '/locales/{{locale}}/{{key}}.content.json', // Equivalent using template string     * }     * ```     *     * Variable list:     *   - `fileName`: The name of the file.     *   - `key`: The key of the content.     *   - `locale`: The locale of the content.     *   - `extension`: The extension of the file.     *   - `componentFileName`: The name of the component file.     *   - `componentExtension`: The extension of the component file.     *   - `format`: The format of the dictionary.     *   - `componentFormat`: The format of the component dictionary.     *   - `componentDirPath`: The directory path of the component.     */    output: ({ fileName, extension }) => `./${fileName}${extension}`,    /**     * Indicates if the components should be saved after being transformed.     *     * - If `true`, the compiler will rewrite the component file in the disk. So the transformation will be permanent, and the compiler will skip the transformation for the next process. That way, the compiler can transform the app, and then it can be removed.     *     * - If `false`, the compiler will inject the `useIntlayer()` function call into the code in the build output only, and keep the base codebase intact. The transformation will be done only in memory.     */    saveComponents: false,    /**     * Inset only content into the generated file. Useful for per-locale i18next or ICU MessageFormat JSON outputs.     *     * - `output: ({ locale, key }) => `./locale/${locale}/${key}.json`,`     */    noMetadata: false,    /**     * Dictionary key prefix     */    dictionaryKeyPrefix: "", // Add an optional prefix for the extracted dictionary keys  },};export default config;
      npx intlayer test         # Test if there is missing translations
      npx intlayer fill         # Fill missing translations
      npx intlayer extract