You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a few buttons for selecting the user language which change the $locale store to the locale string. I had an issue where $locale would get reset to whatever initLocale was in the +layout.js when hovering over links (preload) and when changing the route.
I fixed(?) it by using the following code:
constinitLocale=get(locale) ? get(locale) : "en";// get from cookie, user session, ...awaitloadTranslations(initLocale,pathname);
which seems to work as it uses the $locale store value if it exists, otherwise "en" as a default. (Should probably use cookies/localstorage for this later)
My main question is, is there a better way to do this? I'm very new to i18n.
The text was updated successfully, but these errors were encountered:
Hi @henrikvilhelmberglund!
Your solution is quite tricky as the locale store is shared between users on server. Recommended is to use cookies to keep user’s preferred language.. see example here.
I have a few buttons for selecting the user language which change the $locale store to the locale string. I had an issue where $locale would get reset to whatever initLocale was in the +layout.js when hovering over links (preload) and when changing the route.
I fixed(?) it by using the following code:
which seems to work as it uses the $locale store value if it exists, otherwise "en" as a default. (Should probably use cookies/localstorage for this later)
My main question is, is there a better way to do this? I'm very new to i18n.
The text was updated successfully, but these errors were encountered: