Set cookie to locale that it redirected to, and always redirect (unless manually switched to different locale)
See original GitHub issueWhat problem does this feature solve?
I implemented my own version of detectBrowserLanguage when I was still using an older version of nuxt-i18n and I was happy to see this feature was added in a later version! I just tried it out, and I think the current implementation can be improved, because now it will only redirect the first time, not when a user returns to the main url.
What does the proposed changes look like?
The cookie should be set to the initially detected language, en then always check what the (last selected) language is set to in the cookie. Then we can always redirect to the language stored in the cookie. If the user manually switched language through the switchLocalePath
function, the cookie can be updated with the manually selected language, and also remember this manual overwrite on the next visit.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:16
Top Results From Across the Web
Set cookie to locale that it redirected to, and always ... - GitHub
Then we can always redirect to the language stored in the cookie. If the user manually switched language through the switchLocalePath function, ...
Read more >How to force Next.js to always redirect to a preferred user ...
By default, Next.js automatically detects the user's preferred locale based on the Accept-Language header sent in the page request.
Read more >Localization Redirects with cookies via Variables Support!
A discussion with one of my customers led me to explore if their full localization redirection logic could be moved into the property ......
Read more >Set-Cookie - HTTP - MDN Web Docs
Indicates that the cookie is sent to the server only when a request is made with the https: scheme (except on localhost), and...
Read more >next.config.js: Redirects
Add redirects to your Next.js app. ... Header, Cookie, and Query Matching ... is set source: '/nl/with-locale-manual', destination: '/nl/another', locale: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks. I ended up doing something similar, making a plugin:
@stact despite the naming,
switchLocalePath
just returns URL of current page for given locale. So it wouldn’t really fit to make it set the cookie. Remember it can be used multiple time in a template and then it would change state every time it’s called.