0.0.15 • Published 3 years ago

@os-utils/i18next-express-middleware v0.0.15

Weekly downloads
15
License
MIT
Repository
-
Last release
3 years ago

@os-utils/i18next-express-middleware

Middleware for i18next and express to detect the language. Supports TypeScript.

Getting started

Installation

yarn add @os-utils/i18next-express-middleware

Also install cookie-parser if you need to detect the language from a cookie.

Usage Example

import express from 'express'
import cookieParser from 'cookie-parser'
import i18next from 'i18next'
import { i18nextMiddleware, LanguageDetector } from '@os-utils/i18next-express-middleware'

// Initialize i18next
i18next
  .use(LanguageDetector) // Pass the LanguageDetector middleware
  .init({
    fallbackLng: 'en',

    // Pass the custom options if necessary
    detection: {
      // In what order will the detectors be started
      order: ['cookie', 'header'], // default: ['header']
      
      // Keys used by the detectors
      cookie: 'custom-cookie', // default: i18next
      header: 'custom-header', // default: Accept-Language
    },
  })


const app = express()
app.use(cookieParser())
app.use(i18nextMiddleware(i18next))
0.0.15

3 years ago

0.0.14

4 years ago

0.0.12

4 years ago

0.0.13

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago