Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: language icon display issue #143

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/lib/components/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import { onMount } from 'svelte';
import { page } from '$app/state';
import { language } from '$lib/stores/language'; // Import the global language store
import { browser } from '$app/environment';

let hinagiku = $state('Hinagiku');
let highlight = $state(0);
let hydrated = $state(false);

const translations = {
en: {
Expand All @@ -31,13 +31,11 @@
import { derived } from 'svelte/store';

const flagSrc = derived(language, ($language) => {
return browser
? $language === 'zh'
? '/icons/flag-zh.jpg'
: '/icons/flag-us.png'
: '/icons/flag-us.png';
return $language === 'zh' ? '/icons/flag-zh.jpg' : '/icons/flag-us.png';
});

const fallbackFlagSrc = '/icons/flag-us.png';

onMount(() => {
const interval = setInterval(() => {
let newHighlight;
Expand All @@ -46,7 +44,7 @@
} while (newHighlight === highlight);
highlight = newHighlight;
}, 800);

hydrated = true;
return () => clearInterval(interval);
});

Expand Down Expand Up @@ -88,7 +86,12 @@
{/if}

<!-- Remove the old toggle button and add a dropdown for language selection(PM requested) -->
<Avatar id="language-menu" src={$flagSrc} alt="$language" class="ml-2 cursor-pointer" />
<Avatar
id="language-menu"
src={hydrated ? $flagSrc : fallbackFlagSrc}
alt="language"
class="ml-2 cursor-pointer"
/>
<Dropdown triggeredBy="#language-menu" class="w-36">
<DropdownItem class="flex items-center" on:click={() => setLanguage('en')}>
<img src="/icons/flag-us.png" alt="English" class="mr-2 h-4 w-4" />
Expand Down
Loading