Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

1.2 KB
Raw Blame
import {Select} from "@mantine/core";
import {availableLocales, dynamicActivateLocale, getClientLocale, getLocaleName, SupportedLocales} from "../../../locales.ts";
import {t} from "@lingui/macro";
import {IconWorld} from "@tabler/icons-react";
import {useLingui} from "@lingui/react";

export const LanguageSwitcher = () => {
    useLingui();

    return (
        <>
            <Select
                leftSection={<IconWorld size={15} color={'#ccc'}/>}
                width={180}
                size={'xs'}
                required
                data={availableLocales.map(locale => ({
                    value: locale,
                    label: getLocaleName(locale as SupportedLocales),
                }))}
                defaultValue={getClientLocale()}
                placeholder={t`English`}
                onChange={(value) => {
                    if (!value) return;
                    document.cookie = `locale=${value};path=/;max-age=31536000`;
                    dynamicActivateLocale(value).finally(() => {
                        window.location.href = window.location.pathname + window.location.search;
                    });
                }}
            />
        </>
    )
}