i18next/i18next-express-middleware is a JavaScript project with 203 stars. [deprecated] can be replaced with i18next-http-middleware
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
var i18next = require("i18next");
var middleware = require("i18next-express-middleware");
var express = require("express");
i18next.use(middleware.LanguageDetector).init({
preload: ["en", "de", "it"],
...otherOptions
});
var app = express();
app.use(
middleware.handle(i18next, {
ignoreRoutes: ["/foo"], // or function(req, res, options, i18next) { /* return true to ignore */ }
removeLngFromUrl: false
})
);
// in your request handler
app.get("myRoute", function(req, res) {
var lng = req.language; // 'de-CH'
var lngs = req.languages; // ['de-CH', 'de', 'en']
req.i18n.changeLanguage("en"); // will not load that!!! assert it was preloaded
var exists = req.i18n.exists("myKey");
var translation = req.t("myKey");
});
// in your views, eg. in pug (ex. jade)
div = t("myKey");
add routes
// missing keys; make sure the body is parsed (i.e. with [body-parser](https://github.com/expressjs/body-parser#bodyparserjsonoptions))
app.post("/locales/add/:lng/:ns", middleware.missingKeyHandler(i18next));
// multiload backend route
app.get("/locales/resources.json", middleware.getResourcesHandler(i18next));
add localized routes
You can add your routes directly to the express app
Detects user language from current request. Comes with support for:
path
cookie
header
querystring
session
Wiring up:
var i18next = require("i18next");
var middleware = require("i18next-express-middleware");
i18next.use(middleware.LanguageDetector).init(i18nextOptions);
As with all modules you can either pass the constructor function (class) to the i18next.use or a concrete instance.
Detector Options
{
// order and from where user language should be detected
order: [/*'path', 'session', */ 'querystring', 'cookie', 'header'],
// keys or params to lookup language from
lookupQuerystring: 'lng',
lookupCookie: 'i18next',
lookupHeader: 'accept-language',
lookupSession: 'lng',
lookupPath: 'lng',
lookupFromPathIndex: 0,
// cache user language
caches: false, // ['cookie']
// optional expire and domain for set cookie
cookieExpirationDate: new Date(),
cookieDomain: 'myDomain',
cookieSecure: true // if need secure cookie
}
Options can be passed in:
preferred - by setting options.detection in i18next.init:
var i18next = require("i18next");
var middleware = require("i18next-express-middleware");
i18next.use(middleware.LanguageDetector).init({
detection: options
});
on construction:
var middleware = require("i18next-express-middleware");
var lngDetector = new middleware.LanguageDetector(null, options);
via calling init:
var middleware = require("i18next-express-middleware");
var lngDetector = new middleware.LanguageDetector();
lngDetector.init(options);
Adding own detection functionality
interface
module.exports = {
name: 'myDetectorsName',
lookup: function(req, res, options) {
// options -> are passed in options
return 'en';
},
cacheUserLanguage: function(req, res, lng, options) {
// options -> are passed in options
// lng -> current language, will be called after init and on changeLanguage
// store it
}
};
adding it
var i18next = require("i18next");
var middleware = require("i18next-express-middleware");
var lngDetector = new middleware.LanguageDetector();
lngDetector.addDetector(myDetector);
i18next.use(lngDetector).init({
detection: options
});
How active is development on i18next/i18next-express-middleware?
The most recent commit recorded on i18next/i18next-express-middleware was 4.8 years ago, based on the GitHub push timestamp. The repository has 50 forks — one of the better signals of community interest.
Is i18next/i18next-express-middleware open source?
Yes — i18next/i18next-express-middleware ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/i18next/i18next-express-middleware.
What license does i18next/i18next-express-middleware use?
i18next/i18next-express-middleware is released under the MIT license. Always verify the LICENSE file directly on GitHub for the authoritative terms — license strings can be edited out of sync with a project's actual stance.
What topics is i18next/i18next-express-middleware associated with?
GitHub's repository topics for i18next/i18next-express-middleware: "express-middleware", "i18n", "i18next", "internationalization", "translation". TopGit's editorial category is open-source.
Where can I see i18next/i18next-express-middleware in action?
The project maintains a homepage at https://github.com/i18next/i18next-http-middleware. The README tab on this page also usually contains screenshots and a quickstart.
Where do I read more about i18next/i18next-express-middleware?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/i18next/i18next-express-middleware is the definitive source.
Read full README in the tab above.
Curious whether i18next-express-middleware is right for you?
Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about i18next-express-middleware.