QuiiBz / next-international

Type-safe internationalization (i18n) for Next.js
https://next-international.vercel.app
MIT License
1.3k stars 61 forks source link

Next-Locale cookie defaults to browser language and not the default language #99

Closed aulonm closed 1 year ago

aulonm commented 1 year ago

Issue Description: When I run the website locally it defaults to en in Next-Locale-cookie, even though I set the middleware to only accept nb and sv. Is it possible to add an option to add the default language that I set and not what my browser says my language is in?

Our sites are based on a domain and not a path. So we develop 1 application, but serve two different instances with two different domains. In norwegian and swedish with the domains .no and .se.

Reproduction Steps: Just run the server and go to localhost:3000/medlem/under and check the console that it adds { Next-Locale: 'en' }. I want this to be nb since I've said that nb is my default language. https://github.com/aulonm/next-international-repro

Expected Behavior: The applications should use the default locale set if there is no next-locale in the users cookies.

Actual Behavior: Defaults to en

Issue Analysis: I'm guessing it is this part that is doing the heavy lifting: https://github.com/QuiiBz/next-international/blob/main/packages/next-international/src/app/middleware/index.ts#L49-L55

Proposed Solution: Add an option to the middleware to set the initial language to the default language set and not what language the browser is.

Additional Information:

Next.js version: 13.4.13 next-international version: 0.8.1

Best regards,

QuiiBz commented 1 year ago

I've released version 0.8.2 which includes #101 and should fix this bug. I'll close the issue but let me know if it still doesn't work, and I'll reopen it.

aulonm commented 1 year ago

This works! Thank you 🙌