https://github.com/hex7c0/browser-language
grab browser language and store on cookie for Nodejs
https://github.com/hex7c0/browser-language
browser-language nodejs
Last synced: 3 months ago
JSON representation
grab browser language and store on cookie for Nodejs
- Host: GitHub
- URL: https://github.com/hex7c0/browser-language
- Owner: hex7c0
- License: gpl-3.0
- Created: 2014-05-13T17:08:45.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2024-03-25T22:51:16.000Z (over 1 year ago)
- Last Synced: 2024-04-14T20:44:39.497Z (about 1 year ago)
- Topics: browser-language, nodejs
- Language: JavaScript
- Homepage: https://github.com/hex7c0/browser-language
- Size: 307 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# [browser-language](https://github.com/hex7c0/browser-language)
[](https://www.npmjs.com/package/browser-language)
[](https://travis-ci.org/hex7c0/browser-language)
[](https://ci.appveyor.com/project/hex7c0/browser-language)
[](https://david-dm.org/hex7c0/browser-language)
[](https://coveralls.io/r/hex7c0/browser-language)Grab browser language and store min value on cookie for [nodejs](http://nodejs.org).
If `browser['Accept-Language'] = it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4`, store `it` on cookie, otherwise, if language is not available, store default language `en`## Installation
Install through NPM
```bash
npm install browser-language
```
or
```bash
git clone git://github.com/hex7c0/browser-language.git
```## API
_Normal_ use inside expressjs project
```js
var language = require('browser-language');
var app = require('express')();app.use(language());
```_Signed_ use inside expressjs project
```js
var language = require('browser-language');
var app = require('express')();
var cookie = require('cookie-parser');app.use(cookie('foo'));
app.use(language({
dictionary: {
_default: 'en',
en: 'en'
},
cookie: 'new_cookie_name',
signed: true
}));
```Check [Cookie options](http://expressjs.com/api.html#res.cookie)
### language(options)
#### options
- `dictionary` - **Object** Accepted language
- `_default` - **String** The dafault value, if request from client cannot be evaluated
- `en` - **String** Set cookie with 'en' value
- `it` - **String** Set cookie with 'it' value
- `..` - **String** Set cookie with '..' value
- `domain` - **String** Domain of cookie *(default "null")*
- `cookie` - **String** Name of cookie *(default "lang")*
- `path` - **String** Path of cookie *(default "/")*
- `maxAge` - **Number** Age of cookie in millisecond *(default "1 year")*
- `httpOnly` - **Boolean** Flag for http only cookie *(default "false")*
- `secure` - **Boolean** Flag for using cookie over TLS/SSL *(default "false")*
- `signed` - **Boolean** Will use the secret passed to cookieParser(secret) to sign the value *(default "false")*
- `encryption` - **Object** Configuration for [cookie-encryption](https://github.com/hex7c0/cookie-encryption) *(defaut "deactivated")*`dictionary` object with correct value to be added, otherwise using a default dictionary inside *./lib/dictionary.js*
## Examples
Take a look at my [examples](examples)
### [License GPLv3](LICENSE)