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)

Most upvoted comments

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 add localePath prop to config in next-i18next.config.js file:

localePath: path.resolve('./public/locales')

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