I'm using next-i18next to handle internationalization of my next.js app.
Is it possible to change default language dynamically? For example based on the top level domain?
const defaultLanguage = topLevelDomain === "de" : "de" ? "it";
EDIT: I'm also using localeSubpaths so that's why I'm trying to investigate the topic.
For someone who use Nextjs
v10.0.0up as written here, we have to use the newest configurations.next-i18next.config.jsnext.config.jsAnd to change the language we have to use
next/linkandnext/router:But you have to bear in mind, that:
At first render, the default language will always refer to the
Accept- Languageheader sent by the browser. In other words, the default language will be based on your target user's browser language settings.Let say that
Accept-Languageheader sent by the browser is as follows (bothdeanditexists):then the default language will be
German, ignoring the configurationdefaultLocaleatnext-i18next.config.js.If both
deanditnot listed inAccept-Languagefor example:then the default language will be
Italianfollowing the configuration we made.For development purposes, we can change the browser language settings (I use google chrome) at
chrome://settings/?search=languageand order the languages based on your preference.We can set the default language for the next render by programmatically add
NEXT_LOCALEcookies to the target user's browser, based on their selection. Example:Always check the documentation to get the newest update.