next.js - How to define custom json files in next-i18next - Stack Overflow

admin2025-04-22  1

I am having a Nextjs Typescript application in which I am trying to implement next-i18nnext for internationalization This is my next-i18next.config.mjs file

import path from 'path';

const nextI18NextConfig = {
  debug: process.env.NODE_ENV == 'development',
  i18n: {
    defaultLocale: 'en',
    locales: ['en', 'fr'], // Add more locales if needed
  },
  // Direct path to the locale files
  localePath: typeof window === 'undefined' ? path.resolve('./public/locales') : '/locales',

  fallbackLng: 'en',
  interpolation: {
    escapeValue: false, // not needed for React
  },
};

export default nextI18NextConfig;

I want to keep the language files as public/locales/en.json, public/locales/fr.json

but I am not able to read them during translations because this expects the default folder structure as

public/locales/en/common.json

and so on. How can I achieve the customization I mentioned above. What changes I need to do in next-i18next.config.mjs file

转载请注明原文地址:http://anycun.com/QandA/1745300517a90565.html