Creation:2026-01-21Last update:2026-01-21
Reference this doc to your favorite AI assistantChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Init doc"v8.0.01/21/2026
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 documentationCopy
Copy doc Markdown to clipboard
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
Copy code
Copy the code to the clipboard
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:
- Locale Detection: It checks cookies, headers (like
Accept-Language), and URL parameters to determine the user's locale. - Context Setup: it populates
res.localswith:locale: The detected locale.t: A translation function bound to the detected locale.getIntlayer: A function to retrieve dictionaries bound to the detected locale.
- Async Local Storage: it sets up a context that allows the use of global
tandgetIntlayerfunctions imported fromexpress-intlayerwithin the request flow.