Navigation und Content-Pages so angepasst, dass über einen Language-Chooser die Sprache der Seite gewechselt werden kann und automatisch auch der reload der Content-Page angestoßen wird.

This commit is contained in:
2022-05-25 15:37:15 +02:00
parent 516c35dcb4
commit 9188148fe7
7 changed files with 78 additions and 30 deletions

View File

@@ -1,4 +1,5 @@
<script lang="ts">
import { navigate } from "svelte-routing"
import { navigations, location, currentLang } from "../../store"
$: languages = []
@@ -12,19 +13,21 @@
languages = languages
}
$: console.log($location)
const setLanguage = (lang: string) => {
let path = $location.path.split("/")
path[1] = lang
$location.path = path.join("/")
$currentLang = lang
navigate($location.path + $location.search, { replace: true })
}
</script>
<div class="language-chooser">
{#each languages as language}
<div
class="lang"
class:active="{$currentLang === language}"
on:click="{() => {
$currentLang = language
}}"
>
{language}
{#each languages as lang}
<div class="lang" class:active="{$currentLang === lang}" on:click="{() => setLanguage(lang)}">
{lang}
</div>
{/each}
</div>

View File

@@ -4,7 +4,7 @@
import { mdiMenu } from "@mdi/js"
import { links } from "svelte-routing"
import { navigations } from "../../store"
import { navigations, currentLang } from "../../store"
import LanguageChooser from "./LanguageChooser.svelte"
@@ -14,8 +14,9 @@
let showMobileNav: boolean = false
$: {
navigation = null
$navigations?.map((nav) => {
if (nav.ident === ident) {
if (nav.ident === ident && nav.locale === $currentLang) {
navigation = nav
}
})