i18n 用于国际化目的。
当用户在url上发送语言代码时,我将像这样更改i18n的语言 http://localhost:8080/signup?language=en为此,我正在使用服务器扩展 OnRequest。这样每条路线都会全局,但是出现问题的是当我在OnRequest中访问i18n时,它显示未定义的错误但是在路由处理程序中,它显示了 happy-i18n 的所有属性这是我的代码和输出
server.ext('onRequest', function(request, response){
console.log("pre handler");
console.log(request.i18n);
return response.continue();
});
输出:定义
但在处理程序中
{
method : 'POST',
path : "/signup",
config : {
tags : ['api'],
description : 'Customer signup',
},
handler: function(request, response){
console.log(request.i18n);
}
}
输出:
{ __: [Function],
__n: [Function],
getLocale: [Function],
setLocale: [Function],
getCatalog: [Function],
locale: 'en'
}
您需要
使用 onPostAuth 扩展点,因为您使用的模块在请求对象生命周期期间操作 onPreAuth 扩展点中的请求对象。