2025-01-14 19:22:41 -06:00
|
|
|
import {} from '@blitzkit/core';
|
2025-01-10 14:37:29 -06:00
|
|
|
import {
|
|
|
|
|
DEFAULT_LOCALE,
|
2025-01-16 14:10:28 -06:00
|
|
|
STRINGS,
|
2025-01-10 14:37:29 -06:00
|
|
|
SUPPORTED_LOCALES,
|
2025-01-14 19:22:41 -06:00
|
|
|
SUPPORTED_LOCALE_FLAGS,
|
|
|
|
|
} 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';
|
2025-01-15 13:10:57 -06:00
|
|
|
import { BlitzKitTheme } from './BlitzKitTheme';
|
|
|
|
|
|
|
|
|
|
export function LocaleSwitcherThemeWrapper({ locale }: LocaleAcceptorProps) {
|
|
|
|
|
return (
|
|
|
|
|
<BlitzKitTheme style={{ background: 'transparent' }}>
|
|
|
|
|
<LocaleSwitcher locale={locale} />
|
|
|
|
|
</BlitzKitTheme>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-01-10 14:37:29 -06:00
|
|
|
|
|
|
|
|
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);
|
2025-01-15 13:10:57 -06:00
|
|
|
|
|
|
|
|
let rawPath = window.location.pathname;
|
|
|
|
|
|
|
|
|
|
for (const supportedLocale of SUPPORTED_LOCALES) {
|
|
|
|
|
if (window.location.pathname.startsWith(`/${supportedLocale}`)) {
|
|
|
|
|
rawPath = rawPath.replace(`/${supportedLocale}`, '');
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.location.pathname = `${
|
|
|
|
|
locale === DEFAULT_LOCALE ? '' : `/${locale}`
|
|
|
|
|
}${rawPath}`;
|
2025-01-10 20:46:15 -06:00
|
|
|
}}
|
|
|
|
|
>
|
2025-04-21 17:01:32 -05:00
|
|
|
<Select.Trigger variant="classic" />
|
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]}{' '}
|
2025-01-16 14:10:28 -06:00
|
|
|
{STRINGS[locale].common.locales[locale]}
|
2025-01-10 20:46:15 -06:00
|
|
|
</Select.Item>
|
|
|
|
|
))}
|
|
|
|
|
</Select.Content>
|
|
|
|
|
</Select.Root>
|
2025-01-10 14:37:29 -06:00
|
|
|
);
|
|
|
|
|
}
|