--- createdAt: 2026-01-21 updatedAt: 2026-09-27 priority: 5 title: intlayer Express Middleware Documentation | express-intlayer description: "The intlayer middleware for Express detects the user's locale and exposes t and getIntlayer through res.locals in your handlers." keywords: - intlayer - express - middleware - Intlayer - intlayer - Internationalization - Documentation slugs: - doc - packages - express-intlayer - intlayer history: - version: 8.0.0 date: 2026-01-21 changes: "Init doc" author: aymericzip --- # 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.