Next.js Discord

Discord Forum

Language Switcher with Cookies

Answered
Bigheaded ant posted this in #help-forum
Open in Discord
Bigheaded antOP
I wanted to create my own blog with this [tailwind template app](https://tailwind-nextjs-starter-blog.vercel.app/).
I somewhat implemented the "LanguageSwitch" function similar to the ThemeSwitch.
However the language doesnt seem to be saved throughout the interactions. Reloading the website or going into a different page causes the language to reset.

As an example I've modified 404 page to use the current language based on the data in public/static/languages folder: https://pastebin.com/8TTd67S6 (Yes, I made it client side. Otherwise I wouldnt be able to import the language at all)

Code:
components/LanguageSwitch.tsx: https://pastebin.com/TtSrEmzr
components/Language.tsx: https://pastebin.com/YsueCLdX
Answered by Quokka
I recommend going with an i18n library like next-intl to avoid headaches instead.
View full answer

2 Replies

I recommend going with an i18n library like next-intl to avoid headaches instead.
Answer
@Quokka I recommend going with an i18n library like `next-intl` to avoid headaches instead.
Bigheaded antOP
Is it possible to use not-found with it?
It seems like NJS doesnt want to recognize not-found.tsx file and doesnt render it at all. Instead it renders the default 404 error.
Not to mention the app throws 404 on every page :/

nvm Im stupid. Fixed it. Thanks, closing