Installations
npm install koa-locales2
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=4.0.0
Node Version
6.9.5
NPM Version
3.10.10
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
demohi
Download Statistics
Total Downloads
2,724
Last Day
1
Last Week
3
Last Month
32
Last Year
187
GitHub Statistics
NOASSERTION License
1 Stars
55 Commits
3 Watchers
1 Branches
1 Contributors
Updated on Dec 13, 2017
Package Meta Information
Latest Version
1.6.0
Package Id
koa-locales2@1.6.0
Size
4.32 kB
NPM Version
3.10.10
Node Version
6.9.5
Total Downloads
Cumulative downloads
Total Downloads
2,724
Last Day
-50%
1
Compared to previous day
Last Week
-66.7%
3
Compared to previous week
Last Month
146.2%
32
Compared to previous month
Last Year
13.3%
187
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
koa-locales
koa locales, i18n solution for koa:
- All locales resources location on
options.dirs
. - resources file supports:
*.js
,*.json
and*.properties
, see examples. - One api:
__(key[, value, ...])
. - Auto detect request locale from
query
,cookie
andheader: Accept-Language
.
Installation
1$ npm install koa-locales --save
Quick start
1var koa = require('koa'); 2var locales = require('koa-locales'); 3 4var app = koa(); 5var options = { 6 dirs: [__dirname + '/locales', __dirname + '/foo/locales'], 7}; 8locales(app, options);
API Reference
locales(app, options)
Patch locales functions to koa app.
- {Application} app: koa app instance.
- {Object} options: optional params.
- {String} functionName: locale function name patch on koa context. Optional, default is
__
. - {String} dirs: locales resources store directories. Optional, default is
['$PWD/locales']
. - {String} defaultLocale: default locale. Optional, default is
en-US
. - {String} queryField: locale field name on query. Optional, default is
locale
. - {String} cookieField: locale field name on cookie. Optional, default is
locale
. - {Object} localeAlias: locale cookie value map. Optional, default is {}.
- {String|Number} cookieMaxAge: set locale cookie value max age. Optional, default is
1y
, expired after one year.
- {String} functionName: locale function name patch on koa context. Optional, default is
1locales({ 2 app: app, 3 dirs: [__dirname + '/app/locales'], 4 defaultLocale: 'zh-CN', 5}));
context.__(key[, value1[, value2, ...]])
Get current request locale text.
1function* home() { 2 this.body = { 3 message: this.__('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'
Usage on template
1this.state.__ = this.__.bind(this);
nunjucks example:
1{{ __('Hello, %s', user.name) }}
License

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-02-10
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