Skip to content

Commit

Permalink
fix: Lang toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
kiosion committed Sep 24, 2023
1 parent 79603ba commit 08363f7
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions svelte-app/src/components/controls/language-toggle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
import Icon from '$components/icon.svelte';
import Tooltip from '$components/tooltip.svelte';
const handleClick = (event: Event, lang: string) => {
const handleClick = (event: Event, lang: (typeof APP_LANGS)[number]) => {
event.preventDefault();
if ($page?.url?.pathname?.startsWith(`/${lang}`)) {
return;
}
goto(
$linkTo(
`${$page.url.pathname}${$page.url.hash}`,
$page.url.searchParams,
APP_LANGS[1]
),
$linkTo(`${$page.url.pathname}${$page.url.hash}`, $page.url.searchParams, lang),
{
invalidateAll: true,
replaceState: true
Expand All @@ -33,17 +29,19 @@

<Hoverable>
<Tooltip
text={$t($currentLang === 'en' ? 'Switch to french' : 'Switch to english')}
text={$t($currentLang === APP_LANGS[0] ? 'Switch to french' : 'Switch to english')}
delay={150}
fixed
>
<button
class="focusOutline h-[20px] w-[20px] rounded-sm hover:text-accent-light dark:hover:text-accent-dark {$$props.class ||
''}"
aria-label={$t($currentLang === 'en' ? 'Switch to french' : 'Switch to english')}
aria-label={$t(
$currentLang === APP_LANGS[0] ? 'Switch to french' : 'Switch to english'
)}
tabindex="0"
on:click={(e) => {
handleClick(e, $currentLang === 'en' ? 'fr' : 'en');
handleClick(e, $currentLang === APP_LANGS[0] ? APP_LANGS[1] : APP_LANGS[0]);
}}
>
<Icon icon="script" />
Expand Down

0 comments on commit 08363f7

Please sign in to comment.