Replies: 2 comments
-
Hi @eikaramba!
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Also, maybe you could get inspired here to figure out how to setup Svelte contexts.. |
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
-
Problem
I am using the router example so i have
[lang]
folder in the routes and using hooks.js and __layout accordingly to asses the correct language.Let's say i have a logout endpoint, which is logging out the user and redirecting him to the root
/<lang>
route.Of course i can use
locale.get()
in the server endpoint like this:However because stores are shared between request on the server this is problematic when using multiple requests and will actually not result in the correct locale.
A simple was to test this is to
=>This will redirect to Language A in Browser B because the locale is still set to A.
Possible Solutions
There are ways to handle this with setting the context. Honestly i haven't tried it and it would be better to integrate it into the library here if it is feasible (unfortunately this would mean a heavy coupling to svelte)
What are your thoughts on that? Should we completely avoid using
locale.get()
?In that case the language would need to be fetched from the path and if not set from the accept-language header, duplicating the code already there in the hooks.js file. In that case one could maybe export the locale from the hook.js file to the locals variable of sveltekit and use that instead. However if i need to use the
t
method to translate stuff, it would still use the wrong language.Also it is possible to execute
locale.set(langFromPath)
everytime in the hooks.js file. I am not sure if that is a good idea or not, because it can still maybe lead to race conditions if request get processed in parallel.Beta Was this translation helpful? Give feedback.
All reactions