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. Environment
    3. Fastify
    Creation:2025-12-30Last update:2026-05-06
    See the application template on GitHub

    This page has an application template available.

    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 Solid useIntlayer API usage to direct property access"
      v8.9.05/4/2026
    2. "Add init command"
      v7.6.012/31/2025
    3. "Initial history"
      v7.6.012/31/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

    Translate your Fastify backend website using Intlayer | Internationalization (i18n)

    fastify-intlayer is a powerful internationalization (i18n) plugin for Fastify applications, designed to make your backend services globally accessible by providing localized responses based on the client's preferences.

    See package implementation on GitHub: https://github.com/aymericzip/intlayer/tree/main/packages/fastify-intlayer

    Practical Use Cases

    • Displaying Backend Errors in User's Language: When an error occurs, displaying messages in the user's native language improves understanding and reduces frustration. This is especially useful for dynamic error messages that might be shown in front-end components like toasts or modals.
    • Retrieving Multilingual Content: For applications pulling content from a database, internationalization ensures that you can serve this content in multiple languages. This is crucial for platforms like e-commerce sites or content management systems that need to display product descriptions, articles, and other content in the language preferred by the user.
    • Sending Multilingual Emails: Whether it's transactional emails, marketing campaigns, or notifications, sending emails in the recipient’s language can significantly increase engagement and effectiveness.
    • Multilingual Push Notifications: For mobile applications, sending push notifications in a user's preferred language can enhance interaction and retention. This personal touch can make notifications feel more relevant and actionable.
    • Other Communications: Any form of communication from the backend, such as SMS messages, system alerts, or user interface updates, benefits from being in the user's language, ensuring clarity and enhancing the overall user experience.

    By internationalizing the backend, your application not only respects cultural differences but also aligns better with global market needs, making it a key step in scaling your services worldwide.

    Getting Started

    ide.intlayer.org

    See Application Template on GitHub.

    Installation

    To begin using fastify-intlayer, install the package using npm:

    bash
    Copy code

    Copy the code to the clipboard

    npm install intlayer fastify-intlayernpx intlayer init

    Setup

    Configure the internationalization settings by creating an intlayer.config.ts in your project root:

    intlayer.config.ts
    Copy code

    Copy the code to the clipboard

    import { Locales, type IntlayerConfig } from "intlayer";
    
    const config: IntlayerConfig = {
      internationalization: {
        locales: [
          Locales.ENGLISH,
          Locales.FRENCH,
          Locales.SPANISH_MEXICO,
          Locales.SPANISH_SPAIN,
        ],
        defaultLocale: Locales.ENGLISH,
      },
    };
    
    export default config;

    Declare Your Content

    Create and manage your content declarations to store translations:

    src/index.content.ts
    Copy code

    Copy the code to the clipboard

    import { t, type Dictionary } from "intlayer";
    
    const indexContent = {
      key: "index",
      content: {
        exampleOfContent: t({
          en: "Example of returned content in English",
          fr: "Exemple de contenu renvoyé en français",
          "es-ES": "Ejemplo de contenido devuelto en español (España)",
          "es-MX": "Ejemplo de contenido devuelto en español (México)",
        }),
      },
    } satisfies Dictionary;
    
    export default indexContent;
    Your content declarations can be defined anywhere in your application as soon as they are included into the contentDir directory (by default, ./src). And match the content declaration file extension (by default, .content.{json,ts,tsx,js,jsx,mjs,cjs}).
    For more details, refer to the content declaration documentation.

    Fastify Application Setup

    Setup your Fastify application to use fastify-intlayer:

    src/index.ts
    Copy code

    Copy the code to the clipboard

    import Fastify from "fastify";
    import { intlayer, t, getDictionary, getIntlayer } from "fastify-intlayer";
    import dictionaryExample from "./index.content";
    
    const fastify = Fastify({ logger: true });
    
    // Load internationalization plugin
    await fastify.register(intlayer);
    
    // Routes
    fastify.get("/t_example", async (_req, reply) => {
      return t({
        en: "Example of returned content in English",
        fr: "Exemple de contenu renvoyé en français",
        "es-ES": "Ejemplo de contenido devuelto en español (España)",
        "es-MX": "Ejemplo de contenido devuelto en español (México)",
      });
    });
    
    fastify.get("/getIntlayer_example", async (_req, reply) => {
      return getIntlayer("index").exampleOfContent;
    });
    
    fastify.get("/getDictionary_example", async (_req, reply) => {
      return getDictionary(dictionaryExample).exampleOfContent;
    });
    
    // Start server
    const start = async () => {
      try {
        await fastify.listen({ port: 3000 });
      } catch (err) {
        fastify.log.error(err);
        process.exit(1);
      }
    };
    
    start();

    Compatibility

    fastify-intlayer is fully compatible with:

    • react-intlayer for React applications
    • next-intlayer for Next.js applications
    • vite-intlayer for Vite applications

    It also works seamlessly with any internationalization solution across various environments, including browsers and API requests. You can customize the middleware to detect locale through headers or cookies:

    intlayer.config.ts
    Copy code

    Copy the code to the clipboard

    import { Locales, type IntlayerConfig } from "intlayer";
    
    const config: IntlayerConfig = {
      // ... Other configuration options
      middleware: {
        headerName: "my-locale-header",
        cookieName: "my-locale-cookie",
      },
    };
    
    export default config;

    By default, fastify-intlayer will interpret the Accept-Language header to determine the client's preferred language.

    For more information on configuration and advanced topics, visit our documentation.

    Configure TypeScript

    fastify-intlayer leverages the robust capabilities of TypeScript to enhance the internationalization process. TypeScript's static typing ensures that every translation key is accounted for, reducing the risk of missing translations and improving maintainability.

    Ensure the autogenerated types (by default at ./types/intlayer.d.ts) are included in your tsconfig.json file.

    tsconfig.json
    Copy code

    Copy the code to the clipboard

    {  // ... Your existing TypeScript configurations  "include": [    // ... Your existing TypeScript configurations    ".intlayer/**/*.ts", // Include the auto-generated types  ],}

    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.

    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:

    .gitignore
    Copy code

    Copy the code to the clipboard

    # Ignore the files generated by Intlayer.intlayer
    NestJS
    Hono
    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 intlayer fastify-intlayernpx intlayer init
      {  // ... Your existing TypeScript configurations  "include": [    // ... Your existing TypeScript configurations    ".intlayer/**/*.ts", // Include the auto-generated types  ],}
      # Ignore the files generated by Intlayer.intlayer