Creation:2026-01-21Last update:2026-01-21

    intlayer Express Middleware Documentation

    The intlayer middleware for Express detects the user's locale and provides translation functions through the res.locals object. It also enables the use of the t and getIntlayer functions throughout your request handlers.

    Usage

    ts
    import express from "express";import { intlayer } from "express-intlayer";const app = express();app.use(intlayer());app.get("/", (req, res) => {  const content = res.locals.t({    en: "Hello",    fr: "Bonjour",  });  res.send(content);});

    Description

    The middleware performs the following tasks:

    1. Locale Detection: It checks cookies, headers (like Accept-Language), and URL parameters to determine the user's locale.
    2. Context Setup: it populates res.locals with:
      • locale: The detected locale.
      • t: A translation function bound to the detected locale.
      • getIntlayer: A function to retrieve dictionaries bound to the detected locale.
    3. Async Local Storage: it sets up a context that allows the use of global t and getIntlayer functions imported from express-intlayer within the request flow.