我想根据i18next-express-middleware库检测到的语言来加载资源。您能告诉我如何正确制作吗? 我有一个向端点发出请求并进行i18next初始化后的想法,但这似乎是错误的方式。
我有以下代码:
import express from 'express';
import i18next from "i18next";
import middleware from "i18next-express-middleware";
import manifestHelpers from 'express-manifest-helpers';
import Backend from 'i18next-node-remote-backend';
i18next
.use(Backend)
.use(middleware.LanguageDetector)
.init({
ns: 'common',
backend: {
loadPath: 'https://site/localization/{{ns}}?lang={{lng}}'
}
})
.then(data => {
console.log(i18next.getResourceBundle('uk', 'common')) // undefined
});
const app = express();
app.use(middleware.handle(i18next));
app.use((req, res, next) => {
console.log(req.language); // uk
req.store = configureStore();
return next();
});