
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
ui-lang-detector
Advanced tools
Express.js middleware to detect UI language to be used to serve content
Express.js middleware to detect UI language to be used to serve content.
As soon as you support a website that serves multilingual UI, you want to send the user your content in the language the user prefer. If this is a first-time visitor, you may want to try to guess the most appropriate language from the Accept-Language
header. Later on, you will have a chance to ask the user what language they prefer and store this information with the user account data, or send a special cookie to the user agent.
This middleware extends the Request object with req.uilang
property following these steps:
First, check if the special cookie has come with the request. If so, ok - use it.
If no cookie detected, analyze the Accept-Language
header and choose the most preferable language.
If nothing helps, use the provided default value.
All language codes are lowercased (e.g., en
, en-us
etc).
$ npm install ui-lang-detector --save
const app = require('express')();
const uiLangDetector = require('ui-lang-detector');
// Set up options
const options = {
cookieName: 'lang',
defaultLang: 'en'
};
// Mount the middleware
app.use(uiLangDetector(options));
// Use on routes
app.get('/some_path', function (req, res) {
const uiLanguage = req.uilang;
// etc
});
options
Type: Object
Type: String
Optional. The cookie name being used to store UI language. If omitted, cookies are not processed.
Type: String
Default language code to use.
[2.0.0] - 2016-10-15
FAQs
Express.js middleware to detect UI language to be used to serve content
The npm package ui-lang-detector receives a total of 5 weekly downloads. As such, ui-lang-detector popularity was classified as not popular.
We found that ui-lang-detector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.