Gathering detailed insights and metrics for @webaifei/koa-locales
Gathering detailed insights and metrics for @webaifei/koa-locales
Gathering detailed insights and metrics for @webaifei/koa-locales
Gathering detailed insights and metrics for @webaifei/koa-locales
npm install @webaifei/koa-locales
Typescript
Module System
Min. Node Version
Node Version
NPM Version
51
Supply Chain
88.3
Quality
66
Maintenance
50
Vulnerability
95.6
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
NOASSERTION License
69 Stars
70 Commits
31 Forks
12 Watchers
6 Branches
22 Contributors
Updated on Jan 11, 2025
Latest Version
1.12.13
Package Id
@webaifei/koa-locales@1.12.13
Unpacked Size
18.86 kB
Size
6.88 kB
File Count
5
NPM Version
lerna/4.0.0/node@v14.16.0+x64 (darwin)
Node Version
14.16.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
koa locales, i18n solution for koa:
options.dirs
and also surport danymic update resources with updatei18nResources
.*.js
, *.json
, *.yml
, *.yaml
and *.properties
, see examples.__(key[, value, ...])
.query
, cookie
and header: Accept-Language
.1$ npm install @ok/koa-locales --save
1const koa = require('koa'); 2const locales = require('koa-locales'); 3 4const app = koa(); 5const options = { 6 dirs: [__dirname + '/locales', __dirname + '/foo/locales'], 7}; 8locales(app, options);
locales(app, options)
Patch locales functions to koa app.
__
.['$PWD/locales']
.en-US
.locale
.locale
.''
.{}
.1y
, expired after one year.1locales({ 2 app: app, 3 dirs: [__dirname + '/app/locales'], 4 defaultLocale: 'zh-CN', 5});
The key options.localeAlias
allows to not repeat dictionary files, as you can configure to use the same file for es_ES for es, or en_UK for en.
1locales({ 2 localeAlias: { 3 es: es_ES, 4 en: en_UK, 5 }, 6});
context.__(key[, value1[, value2, ...]])
Get current request locale text.
1async function home(ctx) { 2 ctx.body = { 3 message: ctx.__('Hello, %s', 'fengmk2'), 4 }; 5}
Examples:
1__('Hello, %s. %s', 'fengmk2', 'koa rock!') 2=> 3'Hello fengmk2. koa rock!' 4 5__('{0} {0} {1} {1} {1}', ['foo', 'bar']) 6=> 7'foo foo bar bar bar' 8 9__('{a} {a} {b} {b} {b}', {a: 'foo', b: 'bar'}) 10=> 11'foo foo bar bar bar'
context.__getLocale()
Get locale from query / cookie and header.
context.__setLocale()
Set locale and cookie.
context.__getLocaleOrigin()
Where does locale come from, could be query
, cookie
, header
and default
.
app.__(locale, key[, value1[, value2, ...]])
Get the given locale text on application level.
1console.log(app.__('zh', 'Hello')); 2// stdout '你好' for Chinese
1this.state.__ = this.__.bind(this);
Nunjucks example:
1{{ __('Hello, %s', user.name) }}
Pug example:
1p= __('Hello, %s', user.name)
Koa-pug integration:
You can set the property locals on the KoaPug instance, where the default locals are stored.
1app.use(async (ctx, next) => { 2 koaPug.locals.__ = ctx.__.bind(ctx); 3 await next(); 4});
If you are interested on knowing what locale was chosen and why you can enable the debug messages from debug.
There is two level of verbosity:
1$ DEBUG=koa-locales node .
With this line it only will show one line per request, with the chosen language and the origin where the locale come from (queryString, header or cookie).
1$ DEBUG=koa-locales:silly node .
Use this level if something doesn't work as you expect. This is going to debug everything, including each translated line of text.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
security policy file detected
Details
Reason
license file detected
Details
Reason
Found 10/28 approved changesets -- score normalized to 3
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
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
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