Closed MaxTheTurtle0 closed 4 months ago
This is something i've been looking to implement.
This would likely be incompatible with translated pathnames so those couldn't be used anymore. This is because the handle hook where we could do the language detection & work with cookies runs after the reroute hook where the translated pathnames are handled. This will likely just be a limitation
I think it'd be good to have both of those be optional. For example, you might want to redirect users on their first visit to the detected language, or you might display a popup to allow the user to choose whether they wish to keep using the current locale or switch to the detected one.
Similarly, a returning user using a different locale may be intentionally visiting a different locale and I find it can be jarring/annoying to have things like those out of control. Making it optional allows for the developer to implement a way to give control to the user (ie. a popup with the same choices as mentioned before, but with a checkbox to always redirect to the preferred language).
@LorisSigrist I would be okay with both solutions either after or before the first load. As long as it is functionally working.
@LorisSigrist Is the feature shipped, or have you only moved it to linear? (Because I don't see a linked pull request or documentation 🙂 )
Literally being shipped right now
PR
Will it be activated by default after the version upgrade, or do I need to activate it manually?
The new rule is: "If it's ambiguous, use negotiation"
For now you use it by setting prefixDefaultLanguage: "always"
. This makes any navigations to a route without a language prefix ambiguous, which triggers language negotiation.
Negotiation works like so:
paraglide:lang
cookie to see what the user's last language was. Accept-Language
header. After negotiation you will be redirected the the negotiated language.
This will work once v0.9 is out.
@LorisSigrist Where do I need to add this setting? Didn't find something about this in the docs
I only got around to updating the docs now. It's on this page:
https://inlang.com/m/dxnzrydw/paraglide-sveltekit-i18n/localised-routing#localised-routing
@LorisSigrist I am a bit confused now. What's now the suggested procedure if we wish to have autoredirection? Will the prefixDefaultLanguage: "always"
will solve the issue?
Yes, prefixDefaultLanguage: "always"
is what you need to use.
It will always cause language redirection if the language isn't explicitly in the URL
@LorisSigrist can I use the same thing within my nextJS/React setup?
@themataleao
Language Detection is supported in NextJS using custom Routing-Strategies. If a routing-strategy returns undefined
as the language then language-negotiation will happen. However, users currently aren't redirected to the language-specific paths automatically. Instead the detected language is rendered in-place.
@LorisSigrist ok thanks. What would you suggest as the most robust setup for now? Are you planning to make automatic redirects in the future?
@LorisSigrist I think it could help to add also the path to the file at the top of the code block. That could save some seconds of file searching 🙂 https://inlang.com/m/dxnzrydw/paraglide-sveltekit-i18n/localised-routing
Proposal:
Implement an option within the SvelteKit adapter (or applicable adapters) to enable automatic detection of the visitor's browser language. This feature would:
Benefit:
Improves UX