npm install @volcengine/i18n
node端如果有使用koa之类的框架,可以直接写一个中间件进行扩展:
const nodeI18n = require('@volcengine/i18n/dist/node') module.exports = (options) => { const i18n = nodeI18n.init({ lng: 'en', backend: { namespace: 3174, operatorId: 210041130, apiKey: '704dbe7057f510ec8e4aedf71dc34d4f', projectId: 4168, enableWatch: true } }) return async (ctx, next) => { ctx.t = i18n.t await next() } }
如有其他框架需求,可先自行扩展
更改当前应用语种
const i18n = nodeI18n.init({...}) i18n.changeLanguage('en')
运行时对文案进行替换