Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
sg-koa-i18n
Advanced tools
i18n middleware for koa@2.x, use with sg-i18n, you need to use together with koa-locale.
npm i sg-koa-i18n -S
var app = require('koa')();
var locale = require('koa-locale');
var i18n = require('sg-koa-i18n');
// the locale key name defaults to `locale`
locale(app, 'language');
// add i18n middleware
app.use(i18n(app, {
directory: __dirname + '/fixtures/locales',
locales: ['zh-CN', 'en', 'zh-TW'],
defaultLocale: 'zh-CN',
mappings: {
'zh-HK': 'zh-TW'
},
modes: [
'header',
'url',
(ctx) => {
return ctx.headers['locale'];
}
]
}));
// the, u can ust the i18n
app.use(async (ctx, next) => {
// i18n instance
let i18n = ctx.i18n;
// translate
let msg = i18n.__('msg');
let msg2 = ctx.__('msg2');
// ctx.state.locale: object
console.log(ctx.state.locale)
ctx.body = ctx.i18n.__('locales.en')
});
// ctx.state.locale
ctx.state.locale = {
// the finnal used locale
locale: locale,
// the locale detected with modes, no mappings, no default,
detected: localeDetected,
// the detected locale of modes
map: whiteMap,
// the mode that locale detected from
use: use,
}
{
// support locales
locales: ['zh-CN'],
// default locale, must in locales
defaultLocale: 'zh-CN',
// the i18n data directory, absolute path
directory: '',
// the extension of the i18n data file,
// the data of file must be JSON format
extension: '.js',
// the mode to get locale from,
// search by order, use the first matched one
// example: ['Subdomain', 'Cookie', 'Header', 'Query', 'Url', 'TLD']
// https://github.com/koa-modules/locale
modes: ['url'],
// mappings other locales that not in locales to one of the locales
// example: {'zh-HK': 'zh-CN'}
mappings: {},
// clear the locale in path, so can match router later
// /zh-CN/xxx => /xxx
rewrite: true,
}
FAQs
Fork of https://github.com/shared-goals/sg-koa-i18n.git
The npm package sg-koa-i18n receives a total of 0 weekly downloads. As such, sg-koa-i18n popularity was classified as not popular.
We found that sg-koa-i18n demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.