Language detector not really working
FabricioZProx opened this issue ยท 1 comments
๐ Bug Report
I am runing a i18next instance with language detector and i18next-fs-backend.
The language detetor does work properly. First I was using the header detector and my own detector, an although both are able to catch the locale. And the after executing the detector debug log shows:
i18next: languageChanged en
But i18n still uses the fallback option. I must manually call changeLanguage() in order to make it work properly.
After using changeLanguage() is get the same log:
i18next: languageChanged en
But this time language is working properly
To Reproduce
const i18n = require("i18next");
const i18fs = require("i18next-fs-backend");
const i18nMiddleware = require('i18next-http-middleware');
const IOTError = require('../../configuration/errors/IOTError');
const urlLookup = require("./urlLookup")
const path = require("path");
exports.i18nInit = () => {
/*const languageDetector = new i18nMiddleware.LanguageDetector();
languageDetector.addDetector(urlLookup);*/
const options = {
initImmediate: false,
preload: ["es", "en"],
fallbackLng: "es",
fallbackNS: "common",
ns: ["common"],
debug: true,//process.env.VERBOSE_DEBUG,
backend: {
loadPath: path.resolve("./") + "/service/locales/{{lng}}/{{ns}}.json",
},
detection: {
order: ['urlParam'],
caches: false
}
};
i18n.use(languageDetector).use(i18fs).init(options); //TODO add callback for error
return {i18n, i18nMiddleware};
};
the same happens if use order: ['header']
Expected behavior
I was expecting that Language detector will automatically change the language on the request, and that I dont have to manually set changeLanguage
Your Environment
- runtime version: node v12.16.3
-"i18next": "^19.6.2", - os: Windows/Linux
- "i18next": "^19.5.3",
"i18next-fs-backend": "^1.0.7",
"i18next-http-middleware": "^3.0.2",
Can you please create a reproducable example like here: https://github.com/i18next/i18next-http-middleware/tree/master/example/basic so I can run it?