I'm currently utilizing next-translate
. The default recognition of my routes is as follows:
/about <---
/de/about
/es/about
However, I would like to set a specific locale for all paths:
/en/about <---
/de/about
/es/about
Below is the configuration I am using:
next.config.js
const nextTranslate = require('next-translate');
module.exports = nextTranslate({
...
i18n: {
localeDetection: false,
locales: ['en', 'de', 'es'],
defaultLocale: 'en',
}
});
i18n.js
module.exports = {
locales: ['en', 'de', 'es'],
defaultLocale: 'en',
pages: {
'*': ['common']
},
interpolation: {
prefix: '${',
suffix: '}',
},
loadLocaleFrom: (locale, namespace) =>
import(`./translations/${locale}/${namespace}`).then((m) => m.default),
}
It's important to note that I have a language change component that stores the NEXT_LOCALE
cookie. Despite this, when I visit /about
with a previously set cookie value of de
, the router does not redirect me to /de/about
. Instead, it remains at /about
and changes the cookie value to en
...
The current structure of my pages
folder is as follows:
...
pages/
_app.tsx
_document.tsx
about.tsx
...
Should I reorganize it to look like this?
pages/
_app.tsx
_document.tsx
[lang]/ <---
about.tsx
...
If yes, what steps should I take next?
- Extract the preferred locale using
useRouter()
- Retrieve the
NEXT_LOCALE
cookie value - Analyze the
lang
slug
and then decide on the priority? Where should these processes be implemented? In _app.tsx
or in a Higher Order Component?
Are there any necessary rewrites
or redirects
in my next.config.js
, or should I handle these dynamically through Router.push
?