i18next: In Production, translation is not working
Localhost translation works completely fine, but when deployed in production, text is not being translated. Please help am using i18next-express-middleware.
i18next
.use(Backend)
.use(i18nextMiddleware.LanguageDetector)
.init({
backend: {
loadPath: path.join(__dirname + '/locales/{{lng}}.json'),
addPath: __dirname + '/locales/{{lng}}.missing.json'
},
detection: {
order: ['path','cookie','querystring'],
caches: ['cookie']
},
fallbackLng: 'en',
preload: ['en', 'zh-hans'],
saveMissing: true
});
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17 (7 by maintainers)
holy moly…how to get you to understand…it’s not an issue of your i18n config…it’s your server not hosting the JSONs…
To anyone else who finds this ticket looking for a solution for Next.js, I just had to import
path
and addlocalePath
prop to config innext-i18next.config.js
file:This will correctly resolve the path to locale folder in environments like Vercel.
@b-asaf nothing to do where the files are…the path must be reachable from browser…not filesystem