Next.js Discord

Discord Forum

Localizing pathnames with and without language prefix

Unanswered
American Wirehair posted this in #help-forum
Open in Discord
Avatar
American WirehairOP
Hello, in my next 14 app, I'm using next-intl with cookies for translation to 11 languages in my app. There a some static parts in my app that are only in english and not translated.
Now I need to add another language for translating that parts and also the urls, the tricky part for me is now i need to have the language prefix on the url for that translated language. So I need to wrap the whole app with [locale] folder, but now I have prefixes for both. How to handle it dynamically?

8 Replies

Avatar
I would suggest to remove the locale of the cookies and trust the url. The url will be set automatically by a middleware to ensure that you have a locale everytime
Avatar
American WirehairOP
but i dont want to have prefix on the url for each language. For now, I just want that for one language with localized pathnames, others should see the same
Avatar
then you can't use a dynamic url segment. What you can do is: you can use searchParams. If there is a searchparam for lang for example visible, you know that you need to translate it
One example for that is googles documentation:
Image
Avatar
American WirehairOP
how can i handle localizing the pathname if i use searchparams
Avatar
the same as you would do with the searchParam. Instead of getting it from params you can get it from searchPararms. You can see both here: https://nextjs.org/docs/app/api-reference/file-conventions/page
Avatar
@American Wirehair solved?
Avatar
American WirehairOP
i've needed to come up with a different solution for my current needs. but yes problem is solved for me, thanks