[英]Cannot make i18next work in nodeJS express backend
I'm currently trying to add localization to my nodeJS backend but im having trouble.我目前正在尝试将本地化添加到我的 nodeJS 后端,但我遇到了麻烦。
In my frontend (angular) i have an interceptor that sets the language in the header:在我的前端(角度)中,我有一个拦截器,它在 header 中设置语言:
Which succesfully works as can be seen below in 'Accept-Language' in the headers of my request:哪个成功,如下面我请求标题中的“接受语言”所示:
In my backend app.js i import and configure i18next, i18next-fs-backend, i18next-http-middleware and set the path of the locale files (which can also be seen bellow) and:在我的后端 app.js 中,我导入并配置 i18next、i18next-fs-backend、i18next-http-middleware 并设置语言环境文件的路径(也可以在下面看到)和:
But when i try to use the translations in my response it doesn't work, it displays the 'delete_success' and not the translation.但是当我尝试在我的回复中使用翻译时它不起作用,它显示“delete_success”而不是翻译。
Inside my translation file:在我的翻译文件中:
Bellow im posting some stuff that is printed in the req.i18n console.log in case it helps:下面我发布了一些打印在 req.i18n console.log 中的内容,以防有帮助:
bound I18n {
observers: { languageChanged: [ [Function (anonymous)] ] },
options: {
debug: false,
initImmediate: false,
ns: [ 'translation' ],
defaultNS: [ 'translation' ],
fallbackLng: [ 'en' ],
preload: [ 'pt-BR' ],
backend: {
loadPath: './locales/{{lng}}/translation.json',
addPath: '/locales/{{lng}}/{{ns}}.missing.json',
ident: 2,
parse: [Function: parse],
stringify: [Function: stringify]
},
language: 'en',
}
I have no idea what else to try, any tips?我不知道还能尝试什么,有什么建议吗? :( :(
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.