@os-team/i18next-express-middleware
Middleware for i18next and express to detect the user's language.
Usage
Install the package using the following command:
yarn add @os-team/i18next-express-middleware
Install peer dependencies using the following command:
npx install-peerdeps @os-team/i18next-express-middleware
Example
import express from 'express';
import cookieParser from 'cookie-parser';
import i18next from 'i18next';
import {
i18nextMiddleware,
LanguageDetector,
} from '@os-team/i18next-express-middleware';
i18next
.use(LanguageDetector)
.init({
fallbackLng: 'en',
detection: {
order: ['cookie', 'header'],
cookie: 'custom-cookie',
header: 'custom-header',
},
});
const app = express();
app.use(cookieParser());
app.use(i18nextMiddleware(i18next));