Skip to content

Commit

Permalink
feat: 🎸 locale change automatically updates the document lang
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisermann committed Nov 22, 2019
1 parent 3ec297e commit 64c8e55
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 33 deletions.
15 changes: 0 additions & 15 deletions Intl.svelte

This file was deleted.

33 changes: 15 additions & 18 deletions example/src/routes/_layout.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script context="module">
import { locales, locale, waitInitialLocale } from 'svelte-i18n'
import Intl from 'svelte-i18n/Intl.svelte'
import { locales, locale, isLoading, waitInitialLocale } from 'svelte-i18n'
export async function preload() {
return waitInitialLocale({
Expand Down Expand Up @@ -50,20 +49,18 @@
}
</style>

<Intl let:isLoading>
{#if isLoading}
<div class="loading">Loading...</div>
{/if}
{#if $isLoading}
<div class="loading">Loading...</div>
{/if}

<Nav {segment} />
<main>
<select bind:value={$locale}>
{#each $locales as locale}
{#if locale in localeLabels}
<option value={locale}>{localeLabels[locale]}</option>
{/if}
{/each}
</select>
<slot />
</main>
</Intl>
<Nav {segment} />
<main>
<select bind:value={$locale}>
{#each $locales as locale}
{#if locale in localeLabels}
<option value={locale}>{localeLabels[locale]}</option>
{/if}
{/each}
</select>
<slot />
</main>
4 changes: 4 additions & 0 deletions src/client/stores/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ function loadLocale(localeToLoad: string) {

$locale.subscribe((newLocale: string) => {
current = newLocale

if (typeof window !== 'undefined') {
document.documentElement.setAttribute('lang', newLocale)
}
})

const localeSet = $locale.set
Expand Down

0 comments on commit 64c8e55

Please sign in to comment.