fiorentina.gf
fiorentina.gf

Reputation: 57

How to set the default language without /en in Next.js with next-i18next?

I have a Next.js application with internationalization, using next-i18next. Here’s an example app that demonstrates the setup:
Live Demo
GitHub Repository

Currently, when navigating to the root path, it redirects to /en, assuming English as the default language. However, I’d like the default language to be accessible without any language segment, so that:

How can I configure next-i18next to set up the default language without a URL segment?

Upvotes: 0

Views: 111

Answers (1)

Khalid BOUSSAROUAL
Khalid BOUSSAROUAL

Reputation: 76

Change your next-i18next.config.js at the root of your project to something like this:

module.exports = {
  debug: process.env.NODE_ENV === 'development',
  i18n: {
    locales: ['en', 'zh'],
    defaultLocale: 'en',
  },
};

So, if your path matches the defaultLocale, it will remove the prefix. For example, if your path is /en/path, it will become /path. Otherwise, if it's /zh/path, it will stay as it is.

Upvotes: 1

Related Questions