在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:koa-modules/i18n开源软件地址:https://github.com/koa-modules/i18n开源编程语言:JavaScript 100.0%开源软件介绍:koa-i18n
Installation$ npm install koa-i18n Usageconst Koa = require('koa')
const convert = require('koa-convert')
const locale = require('koa-locale') // detect the locale
const render = require('koa-swig') // swig render
const i18n = require('koa-i18n')
const app = new Koa()
// Required!
locale(app)
app.context.render = render({
root: __dirname + '/views/',
ext: 'html'
})
app.use(i18n(app, {
directory: './config/locales',
locales: ['zh-CN', 'en'], // `zh-CN` defualtLocale, must match the locales to the filenames
modes: [
'query', // optional detect querystring - `/?locale=en-US`
'subdomain', // optional detect subdomain - `zh-CN.koajs.com`
'cookie', // optional detect cookie - `Cookie: locale=zh-TW`
'header', // optional detect header - `Accept-Language: zh-CN,zh;q=0.5`
'url', // optional detect url - `/en`
'tld', // optional detect tld(the last domain) - `koajs.cn`
function() {} // optional custom function (will be bound to the koa context)
]
}))
app.use(function (ctx) {
ctx.body = ctx.i18n.__('any key');
})
app.use(convert(function *() {
yield this.render('index')
}))
Dependencies
LicenseMIT |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论