Replies: 5 comments 5 replies
-
To get the full URL of the page, you can use
Example:
As additional information, you might want to look for |
Beta Was this translation helpful? Give feedback.
-
@ticpoi did you solve the issue or find a way to get the locale? |
Beta Was this translation helpful? Give feedback.
-
Got any solution for this? |
Beta Was this translation helpful? Give feedback.
-
Hi, server : const locale = await getLocale(); client : I extract my translate with db progreSql not Json file because i create dashbord to update this for my customer. Sorry for my little English, I'm French. |
Beta Was this translation helpful? Give feedback.
-
I needed to implement a redirect middleware from an external resource and check the incoming original url to see if a redirect exists for it. Stripping the locale away in that case was very suboptimal, to say the least... So for anyone still searching for a solution, as of Next.js 13.1 you now have the possibility to add the You will then be able to extract the original url with request.url or request.nextUrl.href without any normalization or locale stripping. |
Beta Was this translation helpful? Give feedback.
-
Summary
I need to get the full URL of the page containing the locale information to be able to understand if the default locale applied because of "defaultLocale" or applied because of router (Means url contains the locale name)
For a domain based default language decision, we need this information. But we could not get this information on server side of NextJS.
As example
http://localhost:3000/en - This is en, contains en
http://localhost:3000/fr - This is fr, contains fr
http://localhost:3000 - This is en, does not contain en, it applies en because of the default locale in next.config.js
We want to override the default locale on first load based on domain based configuration.
I can get the locale information "context.locale" but cannot be sure why it is "en". Because it is defaultLocale or it is written in the URL.
We tried many things and I am listing below to explain the problem.
1- comparing context.locale === context.defaultLocale (does not mean anything because it does inform me if the URL has it)
2- tried to create cookie in client side by getting information from router and read on server but serverside works first so we cannot get up-to-date information
3- tried to write a middleware and tried read from req.nextURL but it does not have the language information like context.req.url
4- tried to use the req.header.referrer but it is previous pages url and it does not have the required information on first pages and when the user change the language on client side. It has the previous url details.
So the thing that I need to know if the URL contains the language or not, but next.JS router clears this information from everywhere before reaching to server so we cannot reach it.
Thanks for any kind of help.
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions