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. Concept
    3. Content Declaration
    4. Translation
    Creation:2025-08-23Last update:2025-08-23
    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. "Init history"
      v5.5.106/29/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

    Translation

    Defining Translations

    The t function in intlayer allows you to declare content in multiple languages. This function ensures type safety, raising an error if any translations are missing, which is particularly useful in TypeScript environments.

    Here's an example of how to declare content with translations.

    **/*.content.ts
    Copy code

    Copy the code to the clipboard

    import { t, type Dictionary } from "intlayer";
    
    interface Content {
      welcomeMessage: string;
    }
    
    export default {
      key: "multi_lang",
      content: {
        welcomeMessage: t({
          en: "Welcome to our application",
          fr: "Bienvenue dans notre application",
          es: "Bienvenido a nuestra aplicación",
        }),
      },
    } satisfies Dictionary<Content>;

    Configuration for Locales

    To ensure proper translation handling, you can configure the accepted locales in intlayer.config.ts. This configuration allows you to define the languages that your application supports:

    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],
      },
    };
    
    export default config;

    Using Translations in React Components

    With react-intlayer, you can use translations in React components. Here's an example:

    **/*.tsx
    Copy code

    Copy the code to the clipboard

    import type { FC } from "react";
    import { useIntlayer } from "react-intlayer";
    
    const MyComponent: FC = () => {
      const content = useIntlayer("multi_lang");
    
      return (
        <div>
          <p>{content.welcomeMessage}</p>
        </div>
      );
    };
    
    export default MyComponent;

    This component fetches the corresponding translation based on the current locale set in your application.

    Custom Content Objects

    intlayer supports custom content objects for translation, allowing you to define more complex structures while ensuring type safety. Here's an example with a custom object:

    **/*.content.ts
    Copy code

    Copy the code to the clipboard

    import { t, type Dictionary } from "intlayer";
    
    interface ICustomContent {
      title: string;
      content: string;
    }
    
    const customContent = {
      key: "custom_content",
      content: {
        profileText: t<ICustomContent>({
          en: {
            title: "Page Title",
            content: "Page Content",
          },
          fr: {
            title: "Titre de la Page",
            content: "Contenu de la Page",
          },
          es: {
            title: "Título de la Página",
            content: "Contenido de la Página",
          },
        }),
      },
    } satisfies Dictionary;
    
    export default customContent;
    Content Declaration
    Plural
    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.