Skip to content

Svelte(Kit) reactivity without #key #1883

Discussion options

You must be logged in to vote

There are a few things you could try.

You could store the state in an SvelteKit Snapshot and then reload the page when changing languages. That way the state would survive the language change.

You could also try to create an $m store like so, that updates whenever the language changes:

import * as original_m from "./paraglide/messages.js"
import { onSetLanguageTag, languageTag } from "./paraglide/runtime.js"

// only one instance at a time!
export const m = readable<typeof original_m>(original_m, (set) => {
     onSetLanguageTag(() => set(original_m))
});


//Then use it like
$m.hello_world()

This should work, but it has a drawback. Treeshaking no longer works, so all messages will always…

Replies: 2 comments 17 replies

Comment options

You must be logged in to vote
9 replies
@IAPBenediktZwoelfer
Comment options

@IAPBenediktZwoelfer
Comment options

@LorisSigrist
Comment options

@LorisSigrist
Comment options

Answer selected by IAPBenediktZwoelfer
@IAPBenediktZwoelfer
Comment options

Comment options

You must be logged in to vote
8 replies
@LorisSigrist
Comment options

@IAPBenediktZwoelfer
Comment options

@LorisSigrist
Comment options

@IAPBenediktZwoelfer
Comment options

@LorisSigrist
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants