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

express-simple-locale

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-simple-locale

A simple Express middleware to guess the short-locale of a user.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24
increased by26.32%
Maintainers
1
Weekly downloads
 
Created
Source

Note
This project has been deprecated and will not be receiving any updates anymore.
Please, consider using an alternative package.

express-simple-locale

A simple Express middleware to guess the short-locale of a user. It then saves the found locale on the request for further usage.

It tries, in that order:

  1. The locale query parameter.
  2. The cookie specified by cookieName option.
  3. The first entry of accept-language header.
  4. The acceptedLanguages key from the request.
  5. The hostname.locale nested key from the request.

When found, the locale is split on spaces, hyphens, commas, and underscores so only the first part gets returned (en_GB -> en).

Install

npm i --save express-simple-locale

Options

NameTypeDefaultDescription
keyStringlocale the key to save locale to on the request
supportedLocalesString[][] available locales for the app
defaultLocaleStringen locale to fallback to
cookieNameStringlocalecookie to try getting the locale from
queryParamsString|String[]['locale']the query parameter(s) to look the locale from

Example

import locale from "express-simple-locale";

const localeMiddlewareOptions = {
  key: "userLocale",
  supportedLocales: ["en", "fr", "it", "es", "de"],
  defaultLocale: "en",
  cookieName: "c00ki3z",
  queryParams: ["locale", "lang"],
};

express()
  .use(locale(localeMiddlewareOptions))
  .use((request, response, next) => {
    // request.userLocale
  });

Keywords

FAQs

Package last updated on 11 Jul 2022

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