Author:
    Creation:2026-01-30Last update:2026-09-29

    intlayer AdonisJS Middleware Documentation

    The intlayer middleware for AdonisJS detects the user's locale and provides translation functions through the request context. It also enables the use of global translation functions within the request flow.

    Usage

    start/kernel.ts
    router.use([() => import("adonis-intlayer/middleware")]);
    
    start/routes.ts
    import router from "@adonisjs/core/services/router";
    import { t } from "adonis-intlayer";
    
    router.get("/", async () => {
      return t({
        en: "Hello",
        fr: "Bonjour",
      });
    });
    

    Description

    The middleware performs the following tasks:

    1. Locale Detection: It analyzes the request (headers, cookies, etc.) to determine the user's preferred locale.
    2. Context Setup: It populates the request context with locale information.
    Note: To use cookies for locale detection, ensure @adonisjs/cookie is configured and used in your application.