Switching Locales
Switching locales can be done by either directly updating the locale
store or by using the setLocale
function.
However, doing either will not result in any immediate changes to what’s displayed on the site. This is because messages do not automatically rerender when the locale is changed. You will need to trigger a rerender yourself. (Automatic rerendering is on our roadmap.).
The easiest way to trigger a rerender on locale changes is to wrap the root layout using a key
block that reacts to the locale.
src/routes/+layout.svelte
<script>
import { locale } from "$t18s"
</script>
{#key $locale}
<slot/>
{/key}