1.0.0 • Published 2 years ago
user-language-middleware v1.0.0
About
Express middleware to collect and normalize user lang from http headers.
❤️ Awesome Features:
- Easy to recognize request lang by checking
accept-language
http header value. 🔥 - Easy to assign default languages by simple settings definition 🍺
debug
is supported 💪- Easy to use and great test coverage ✅
const express = require('express');
const userLanguageMiddleware = require('user-language-middleware')
const app = express();
app.use(userLanguageMiddleware({
defaultLang: 'en'
}))
app.get('/', (req, res) => {
res.send(`Your supported language ${req.userLang}`);
});
app.listen(3000, () => {
console.log('We are in port 3000!');
});
Usage
Install
npm install user-language-middleware
simple example
const express = require('express');
const userLanguageMiddleware = require('user-language-middleware')
const app = express();
app.use(userLanguageMiddleware({
defaultLang: 'en'
}))
app.get('/', (req, res) => {
res.send(`Your supported language ${req.userLang}`);
});
app.listen(3000, () => {
console.log('We are in port 3000!');
});
Include a list of supported languages
const express = require('express');
const userLanguageMiddleware = require('user-language-middleware')
const app = express();
app.use(userLanguageMiddleware({
defaultLang: 'en',
availableLangs: ['en', 'es', 'ja']
}))
app.get('/', (req, res) => {
res.send(`Your supported language ${req.userLang}`);
});
app.listen(3000, () => {
console.log('We are in port 3000!');
});
Built With
Development only:
Production only:
- debug - Debug the app
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Ulises Gascón - *Initial work- - @ulisesGascon
See also the list of contributors who participated in this project.
License
This project is licensed under the GNU AGPL3.0 License - see the LICENSE.md file for details
Acknowledgments
- This project is under development, but you can help us to improve it! We :heart: FOSS!
1.0.0
2 years ago