Open rsereir opened 1 year ago
This example is based on having the locale in the url (like the old next.js i18n feature) Beside that app directory now strongly recommends server side first. So you need a way to detect the language on serverside -> middleware...
If you only have client side rendering then you can detect the language with the browser-languageDetector plugin or similar and don't need to have the locale in the url.
Thank you @adrai for your answer !
I understand the approach better now. This issue could be useful for other people who, like me, would like to mask the locale of the URL.
What approach can you advise us, knowing that it is indeed recommended to manage this on the server side ?
If i custom the middleware, i just have to set response.cookies.set(cookieName, lngInReferer)
? And for the switcher, use the i18n.changeLanguage() do the job ?
Thank you again for your work.
Beside the client side only approach idk. I'm not part of the Vercel/Next.js team, so you might ask them?
Here a "hacky" example that tries to not rely on the locale to be in the url: https://github.com/i18next/next-13-app-dir-i18next-no-locale-path-example
@adrai Oh okay, thank you for your POC, I took the time to do some tests, but i have 2 errors in webpack: Error: Text content does not match server-rendered HTML.
and Error: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.
with your fork.
Also, i have another strange things:
I tried to investigate but it seems really complicate to understand where is the problem
Like said... hacky... and btw: it's just a warning
Yes i know, but it's not a render issue?
You may ask the vercel/next.js team
@rsereir
Because the languages are not synced the backend renders first with the fallback version and then it renders again with the language detection making both version not match. You can use dynamic to import then and remove ssr. Put I still haven't found a solution that doesn't force me to avoid doing dynamic imports all over the place. If you get any farther plz share
I'm looking for the same thing...
I found this: https://github.com/QuiiBz/next-international?tab=readme-ov-file#rewrite-the-url-to-hide-the-locale
If you use return NextResponse.rewrite(new URL(`/${lng}${req.nextUrl.pathname}`, req.url))
instead of redirect it works
Question
I can't use this example without locale in the router.
I have to mask the locale in URL to avoid override the website language when url is sharing. It's not working when i remove the (lng) folder in the /app directory.
Also, i think why we use the redirect on /${lng} for locale switcher instead of the changeLanguage function of i18n ?
I don't really understand this approach..
Thank you for your help :)