paraglide-js-adapter-next middleware should initially set the language to the user's browser preference #2486
Unanswered
herkulano
asked this question in
[inlang SDK] Feature Requests
Replies: 2 comments
-
cc @opral/inlang-paraglide-js |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for the suggestion @herkulano! The next paraglide update will decouple language detection & routing, which will make implementing the behavior you described a breeze! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The first time a user opens a page and it's not already prefixed the middleware should set the language to the user's preference in the browser: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language
At the moment the middleware is not storing the user's preference, it's relying entirely on the url. This creates the problem that if the user, for some reason, wanted to see the page in English but their browser preference is Portuguese they couldn't.
I believe reason most (maybe all?) i18n middlewares use a cookie for this reason, so that at the first run the "accept-language" header is checked and the cookie is set.
next-i18n-router ignores the pathname completely by default and uses the cookie instead, but gives you the option to change the cookie from the pathname if you prefer that experience:
https://github.com/i18nexus/next-i18n-router?tab=readme-ov-file#serversetcookie-optional
Examples:
https://github.com/i18nexus/next-i18n-router/blob/main/src/i18nRouter.ts
https://github.com/amannn/next-intl/blob/main/packages/next-intl/src/middleware/middleware.tsx
Beta Was this translation helpful? Give feedback.
All reactions