3.0.3 • Published 10 years ago
express-bcp47 v3.0.3
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 inbcp47format for the locale to use when the browser does not send oneacceptLocales, an array of strings inbcp47format 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-Languageheader, to signal that content for this resource varies depending on that header, improving cacheability. Turn this on if you don't set theVaryheader yourself dependent on other values likeCookieorAccept-Typein addition toAccept-Language