Home
Support Forums

Leveraging the NEXT_LOCALE cookie doesn't work on Netilfy

Hi all,
I want to use the NEXT_LOCALE cookie to redirect the corresponded language path automatically.
The functionality is described as the below link.

It can not work correctly on Netlify.
https://sfnetlify.netlify.app/

It works fine on Vercel.
https://sf1.vercel.app/

You can test the functionality by changing the language selector.
image

Test case1:

  1. Choose the Traditional Chinese(zh_TW) 中文(繁體).
  2. Go to the root URL /.
  3. It should show the Traditional Chinese Path: /zh-TW.
  4. The message above the selector will show ‘我是一則訊息 (繁中)’

Test case2:

  1. Choose the Simple Chinese(zh-CN).
  2. Go to the root URL /.
  3. It should show the Simple Chinese Path: /zh-CN.
  4. The message above the selector will show ‘我是一则讯息 (简中)’

Test case3:

  1. Choose the English.
  2. Go to the root URL /.
  3. It should show the Englis (Default Language) Path: /
  4. The message above the selector will show ‘am a message (English)’

Thank you.

Hi @antai0926,

Netlify uses its own nf_lang cookie and the redirects can be setup like explained here: Redirect options | Netlify Docs

1 Like

Hi @hrishikesh
I see. Thanks for your help.

Hi @hrishikesh ,

I install the netlify-cli and use netlify dev command to run local server to test this case.

It works fine that I use NEXT_LOCALE (not nf_lang) in the netlify dev server in the local machine.
When I deploy it to the Netlify platform, it cannot work fine.
I want the development environment as the same as the Netlify platform, so I install the netlify cli to run the netlify dev.
How can I do that let my development environment as the same as the Netlify platform?
That I can find the problem in my local environment immediately not till deploying my project to Netlify platform.
Thank you.

Hi @antai0926,

The problem is that, when you use Netlify CLI, it’s proxying the requests to your SSG’s development server, in your case NextJS’ development server. That server is probably configured to handle NEXT_LOCALE cookie and that’s what’s handling the redirect too.

However, in the production environment, there’s no NextJS development server, thus it won’t work in production. nf_lang, however would work in both environments.

1 Like