Gathering detailed insights and metrics for locale
Gathering detailed insights and metrics for locale
Gathering detailed insights and metrics for locale
Gathering detailed insights and metrics for locale
npm install locale
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.1
Supply Chain
99.5
Quality
79.6
Maintenance
100
Vulnerability
100
License
CoffeeScript (100%)
Total Downloads
12,815,921
Last Day
1,271
Last Week
38,671
Last Month
178,595
Last Year
2,304,860
MIT License
256 Stars
78 Commits
36 Forks
4 Watchers
3 Branches
10 Contributors
Updated on Jan 21, 2025
Minified
Minified + Gzipped
Latest Version
0.1.0
Package Id
locale@0.1.0
Size
6.17 kB
NPM Version
2.7.4
Node Version
0.12.2
Published on
Jun 18, 2016
Cumulative downloads
Total Downloads
Last Day
-10.3%
1,271
Compared to previous day
Last Week
-13.4%
38,671
Compared to previous week
Last Month
-5.2%
178,595
Compared to previous month
Last Year
17.5%
2,304,860
Compared to previous year
3
locale is a node.js module for negotiating HTTP locales for incoming browser requests. It can be used as a standalone module for HTTP or as Express/Connect middleware, or as the server component for an in-browser gettext implementation like JED.
It works like this: you (optionally) tell it the languages you support, and it figures out the best one to use for each incoming request from a browser. So if you support en
, en_US
, ja
, kr
, and zh_TW
, and a request comes in that accepts en_UK
or en
, locale will figure out that en
is the best language to use.
Credits to jed who passed the ownership of the package.
1var http = require("http") 2 , locale = require("locale") 3 , supported = new locale.Locales(["en", "en_US", "ja"]) 4 5http.createServer(function(req, res) { 6 var locales = new locale.Locales(req.headers["accept-language"]) 7 res.writeHeader(200, {"Content-Type": "text/plain"}) 8 res.end( 9 "You asked for: " + req.headers["accept-language"] + "\n" + 10 "We support: " + supported + "\n" + 11 "Our default is: " + locale.Locale["default"] + "\n" + 12 "The best match is: " + locales.best(supported) + "\n" 13 ) 14}).listen(8000)
1var http = require("http") 2 , express = require("express") 3 , locale = require("locale") 4 , supported = ["en", "en_US", "ja"] 5 , app = express() 6 7app.use(locale(supported)) 8 9app.get("/", function(req, res) { 10 res.header("Content-Type", "text/plain") 11 res.send( 12 "You asked for: " + req.headers["accept-language"] + "\n" + 13 "We support: " + supported + "\n" + 14 "Our default is: " + locale.Locale["default"] + "\n" + 15 "The best match is: " + req.locale + "\n" 16 ) 17}) 18 19app.listen(8000)
$ npm install locale
(Note that although this repo is CoffeeScript, the actual npm library is pre-compiled to pure JavaScript and has no run-time dependencies.)
This module exports a function that can be used as Express/Connect middleware. It takes one argument, a list of supported locales, and adds a locale
property to incoming HTTP requests, reflecting the most appropriate locale determined using the best
method described below.
The Locale constructor takes a language tag string consisting of an ISO-639 language abbreviation and optional two-letter ISO-3166 country code, and returns an object with a language
property containing the former and a country
property containing the latter.
The default locale for the environment, as parsed from process.env.LANG
. This is used as the fallback when the best language is calculated from the intersection of requested and supported locales and supported languages has not default.
The Locales constructor takes a string compliant with the Accept-Language
HTTP header, and returns a list of acceptible locales, optionally sorted in descending order by quality score. Second argument is optional default value used as the fallback when the best language is calculated. Otherwise locale.Locale["default"] is used as fallback.
This method takes the target locale and compares it against the optionally provided list of supported locales, and returns the most appropriate locale based on the quality scores of the target locale. If no exact match exists (i.e. language+country) then it will fallback to language
if supported, or if the language isn't supported it will return the default locale.
supported = new locale.Locales(['en', 'en_US'], 'en');
(new locale.Locales('en')).best(supported).toString(); // 'en'
(new locale.Locales('en_GB')).best(supported).toString(); // 'en'
(new locale.Locales('en_US')).best(supported).toString(); // 'en_US'
(new locale.Locales('jp')).best(supported); // supported.default || locale.Locale["default"]
Copyright (c) 2012 Jed Schmidt. See LICENSE.txt for details.
Send any questions or comments here.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 8/28 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More