2023-11-17 00:05:35 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import {
|
|
|
|
Collapse,
|
|
|
|
Dropdown,
|
|
|
|
DropdownItem,
|
2023-11-19 19:27:22 +00:00
|
|
|
DropdownMenu,
|
|
|
|
DropdownToggle,
|
|
|
|
Nav,
|
|
|
|
NavItem,
|
|
|
|
NavLink,
|
|
|
|
Navbar,
|
|
|
|
NavbarBrand
|
2023-11-17 00:05:35 +00:00
|
|
|
} from 'sveltestrap';
|
|
|
|
|
2023-11-17 18:10:46 +00:00
|
|
|
import { page } from '$app/stores';
|
2023-11-19 19:27:22 +00:00
|
|
|
import { locale, locales } from 'svelte-i18n';
|
2023-11-17 00:05:35 +00:00
|
|
|
|
2023-11-17 20:02:31 +00:00
|
|
|
export const setLocale = (lang: string) => () => {
|
|
|
|
locale.set(lang);
|
|
|
|
localStorage.setItem('locale', lang);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getFlagEmoji = (languageCode: string): string | null => {
|
|
|
|
const flagMap: { [key: string]: string } = {
|
|
|
|
en: '🇬🇧', // English flag emoji
|
|
|
|
nl: '🇳🇱', // Dutch flag emoji
|
|
|
|
es: '🇪🇸' // Spanish flag emoji
|
|
|
|
};
|
|
|
|
|
|
|
|
// Convert the language code to lowercase for case-insensitive matching
|
|
|
|
const lowercaseCode = languageCode.toLowerCase();
|
|
|
|
|
|
|
|
// Check if the language code is in the flagMap
|
2023-11-19 19:27:22 +00:00
|
|
|
if (Object.prototype.hasOwnProperty.call(flagMap, lowercaseCode)) {
|
2023-11-17 20:02:31 +00:00
|
|
|
return flagMap[lowercaseCode];
|
|
|
|
} else {
|
|
|
|
// Return null for unsupported language codes
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getLanguageName = (languageCode: string): string | null => {
|
|
|
|
const languageNames: { [key: string]: { [key: string]: string } } = {
|
|
|
|
en: { en: 'English', nl: 'English', es: 'English' },
|
|
|
|
nl: { en: 'Nederlands', nl: 'Nederlands', es: 'Neerlandés' },
|
|
|
|
es: { en: 'Español', nl: 'Spaans', es: 'Español' }
|
|
|
|
};
|
|
|
|
|
|
|
|
const lowercaseCode = languageCode.toLowerCase();
|
|
|
|
|
2023-11-19 19:27:22 +00:00
|
|
|
return Object.prototype.hasOwnProperty.call(languageNames, lowercaseCode)
|
2023-11-17 20:02:31 +00:00
|
|
|
? languageNames[lowercaseCode][lowercaseCode]
|
|
|
|
: null;
|
|
|
|
};
|
2023-11-17 00:05:35 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<Navbar expand="md">
|
|
|
|
<NavbarBrand>₿TClock</NavbarBrand>
|
|
|
|
<Collapse navbar expand="md">
|
|
|
|
<Nav class="me-auto" navbar>
|
|
|
|
<NavItem>
|
2023-11-17 20:02:31 +00:00
|
|
|
<NavLink href="/" active={$page.url.pathname === '/'}>Home</NavLink>
|
2023-11-17 00:05:35 +00:00
|
|
|
</NavItem>
|
|
|
|
<NavItem>
|
2023-11-17 20:02:31 +00:00
|
|
|
<NavLink href="/api" active={$page.url.pathname === '/api'}>API</NavLink>
|
2023-11-17 00:05:35 +00:00
|
|
|
</NavItem>
|
|
|
|
</Nav>
|
|
|
|
<Dropdown inNavbar>
|
2023-11-17 20:02:31 +00:00
|
|
|
<DropdownToggle nav caret>{getFlagEmoji($locale)} {getLanguageName($locale)}</DropdownToggle>
|
2023-11-17 00:05:35 +00:00
|
|
|
<DropdownMenu end>
|
|
|
|
{#each $locales as locale}
|
2023-11-19 19:27:22 +00:00
|
|
|
<DropdownItem on:click={setLocale(locale)}
|
|
|
|
>{getFlagEmoji(locale)} {getLanguageName(locale)}</DropdownItem
|
|
|
|
>
|
2023-11-17 00:05:35 +00:00
|
|
|
{/each}
|
|
|
|
</DropdownMenu>
|
|
|
|
</Dropdown>
|
|
|
|
</Collapse>
|
|
|
|
</Navbar>
|
|
|
|
|
|
|
|
<!-- +layout.svelte -->
|
|
|
|
<slot />
|