Files
blitzkit/packages/website/src/components/LocaleSwitcher.tsx
T

32 lines
916 B
TypeScript
Raw Normal View History

2025-01-14 19:22:41 -06:00
import {} from '@blitzkit/core';
2025-01-10 14:37:29 -06:00
import {
DEFAULT_LOCALE,
SUPPORTED_LOCALES,
2025-01-14 19:22:41 -06:00
SUPPORTED_LOCALE_FLAGS,
localizedStrings,
} from '@blitzkit/i18n';
2025-01-10 20:46:15 -06:00
import { Select } from '@radix-ui/themes';
2025-01-10 14:37:29 -06:00
import type { LocaleAcceptorProps } from '../hooks/useLocale';
export function LocaleSwitcher({ locale }: LocaleAcceptorProps) {
return (
2025-01-10 20:46:15 -06:00
<Select.Root
defaultValue={locale}
onValueChange={(locale) => {
localStorage.setItem('preferred-locale', locale);
window.location.pathname = `/${locale === DEFAULT_LOCALE ? '' : locale}`;
}}
>
<Select.Trigger />
2025-01-10 14:37:29 -06:00
2025-01-10 20:46:15 -06:00
<Select.Content>
{SUPPORTED_LOCALES.map((locale) => (
<Select.Item key={locale} value={locale}>
{SUPPORTED_LOCALE_FLAGS[locale]}{' '}
{localizedStrings[locale].common.locales[locale]}
</Select.Item>
))}
</Select.Content>
</Select.Root>
2025-01-10 14:37:29 -06:00
);
}