Skip to content

Reasonable way to avoid locale resetting on preload? #143

Description

@henrikvilhelmberglund

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:

const initLocale = get(locale) ? get(locale) : "en"; // get from cookie, user session, ...

await loadTranslations(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions