Skip to content
Advertisement

I18N change language in Next.JS

I have some problems with I18N and NextJS. So I configured my I18N, everything works with default locale, but everything crashes if I want to change locale from local storage.
In _app.js I tried to use this function:

JavaScript

I have imported:

JavaScript

When app is loaded it crashes and give error:

JavaScript

I’m using the newest Next.js and I18N What I found is that the program crashes when code reaches i18n.changeLanguage(‘en’). If I use the button to set a new locale, the same error happens. I know that next.js have the option to read locale from URL, but I want to use locale from local storage. Is it possible to use I18N in next js that way? I found too that if I console log i18n it gives me back that i18n have changeLanguage function.
Thanks, everyone for responding! I don’t know what to do at all 🙁

Updated: next.config.js:

JavaScript

Advertisement

Answer

You can change the default local in next.config.js

in _app.js you can get the local in router

JavaScript

i suppose that you have two locales(fr, en)

next.config.js

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement