reqlang
v0.1.3
Published
HTTP Request language
Downloads
6
Readme
Reqlang
Set the language for NodeJS web servers.
Install
npm i reqlang
Usage
The language of the request is looked up in this order:
- Params lang
- From pathname:
/en/hello
- From the lang cookie
- The default language
- Fallback to English (
en
)
var http = require('http')
var rekvest = require('rekvest')
var wcookie = require('wcookie')
var lang = require('reqlang')
// NodeJS web server
var server = http.createServer(function(req, res) {
// Add pathname to request object
rekvest(req)
// Add cookie support
wcookie(req)
// Set the request language
lang(req)
// Set the request language, with default
lang(req, 'en')
req.lang // 'en'
})
ISC Licensed. Enjoy!
Created by Eldøy Projects