From a2c634cef5d7fd15fa7f27547366009f391cff4e Mon Sep 17 00:00:00 2001 From: becarta Date: Wed, 5 Feb 2025 00:22:21 +0100 Subject: [PATCH] changed language selector --- src/components/widgets/Header.astro | 123 +++++++++++++--------------- 1 file changed, 55 insertions(+), 68 deletions(-) diff --git a/src/components/widgets/Header.astro b/src/components/widgets/Header.astro index 4ec78eb..c077e73 100644 --- a/src/components/widgets/Header.astro +++ b/src/components/widgets/Header.astro @@ -1,11 +1,11 @@ --- +// header.astro import { Icon } from 'astro-icon/components'; import Logo from '~/components/Logo.astro'; import ToggleTheme from '~/components/common/ToggleTheme.astro'; import ToggleMenu from '~/components/common/ToggleMenu.astro'; import Button from '~/components/ui/Button.astro'; - import { getHomePermalink } from '~/utils/permalinks'; import { trimSlash, getAsset } from '~/utils/permalinks'; import type { CallToAction } from '~/types'; @@ -46,36 +46,6 @@ const { } = Astro.props; const currentPath = `/${trimSlash(new URL(Astro.url).pathname)}`; - -// Define the available languages. -const languages = [ - { code: 'en', label: 'English' }, - { code: 'nl', label: 'Nederlands' }, - { code: 'de', label: 'Deutsch' }, -]; - -// Get the current URL segments. -const pathSegments = new URL(Astro.url).pathname.split('/').filter(Boolean); -const currentLang = pathSegments[0] || 'en'; - -// When the user selects a new language, update the URL accordingly. -// This function assumes your pages are structured as //page... -function handleLanguageChange(event: Event) { - const select = event.target as HTMLSelectElement; - const selectedLang = select.value; - const newSegments = [...pathSegments]; - - // Replace the first segment if it matches a known language code; otherwise, add it. - if (['en', 'nl', 'de'].includes(newSegments[0])) { - newSegments[0] = selectedLang; - } else { - newSegments.unshift(selectedLang); - } - - const newPath = '/' + newSegments.join('/'); - window.location.href = newPath; -} - ---
-
+
{showToggleTheme && } { showRssFeed && ( @@ -180,43 +150,60 @@ function handleLanguageChange(event: Event) { ) } -
- -
- - + +
+ + +
- - - - +
-
+ + \ No newline at end of file