express-bcp47
v3.0.3
Published
A middleware to parse language selection inputs
Downloads
5
Readme
express-bcp47 -- middleware for parsing locale from headers
SYNOPSIS
var bcp47mw = require('express-bcp47');
app.use(bcp47mw({ defaultLocale: "en-US", vary: true }));
DESCRIPTION
express-bcp47
is a simple middleware that parses the Accept-Language
header from the browser and exposes it to handlers under req.locale
(for handlers) and res.locals.locale
(for the view layer)
There are three parameters to the options object used in the constructor:
defaultLocale
, a string inbcp47
format for the locale to use when the browser does not send oneacceptLocales
, an array of strings inbcp47
format to match up to what the user's browser sends and find a matching locale.vary
, a boolean (defaults to false) that has the middleware send back theVary: Accept-Language
header, to signal that content for this resource varies depending on that header, improving cacheability. Turn this on if you don't set theVary
header yourself dependent on other values likeCookie
orAccept-Type
in addition toAccept-Language