aralroca / next-translate

Next.js plugin + i18n API for Next.js 🌍 - Load page translations and use them in an easy way!
MIT License
2.66k stars 206 forks source link

Change language - compatibility with Next 13 #1210

Open bdetry opened 7 months ago

bdetry commented 7 months ago

What version of this package are you using?

2.6.2 (latest at this day)

What problem do you want to solve?

With Next 13 and app dir compatibly is poor, specially when changing the language in current navigation.

import setLanguage from 'next-translate/setLanguage' gives an error (even with a use client directive): Error: No router instance found. You should only use "next/router" on the client side of your app.

Based on what I see on README note the workaround for now it to use a middleware that appends?lang=es to each navigation. And add "dynamic root directory" [lang]

Readme note : https://www.npmjs.com/package/next-translate#14-use-next-13-app-directory

What do you think is the correct solution to this problem?

Fix import setLanguage from 'next-translate/setLanguage' to allow changing language programmatically. The workaround provided in the readme note suggest changing the files structure of the project and depending on how the app is hosted and built this could require changes on all Links (add /lang path)

Anarbb commented 2 weeks ago

Any workaround on this??