Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ui-lang-detector

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ui-lang-detector

Express.js middleware to detect the UI language that a User Agent prefers analyzing the Accept-Language HTTP header

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

ui-lang-detector

js-semistandard-style

Express.js middleware to detect the UI language that a User Agent prefers analyzing the Accept-Language HTTP header.

As soon as you support a website that serves multilingual UI, you often may want to send a first-time visitor the content in the language most appropriate to them. 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. But the first time you meet your user, all what you have is the Accept-Language header in their HTTP request.

This middleware analyzes the Accept-Language header and stores the most preferable language's code in req.uilang. All language codes are in lowercase.

Installation

$ npm install ui-lang-detector --save

Usage example

const app = require('express')();
const uiLangDetector = require('ui-lang-detector');

// Set up options
const options = {
  defaultLang: "en"
};

// Mount the middleware
app.use(uiLangDetector(options));

// Use on routes
app.get('/some_path', function (req, res) {
  const uiLanguage = req.uilang;
  // etc
});

API

Configuration options

Type: Object

options.defaultLang

Type: String

Default language code to use if no information is available in a request.

Keywords

FAQs

Package last updated on 10 Mar 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc