import {
STRINGS,
SUPPORTED_LOCALE_FLAGS,
type BlitzKitStrings,
} from "@blitzkit/i18n";
import locales from "@blitzkit/i18n/locales.json";
import { Select } from "@radix-ui/themes";
import type { LocaleAcceptorProps } from "../hooks/useLocale";
import { BlitzKitTheme } from "./BlitzKitTheme";
export function LocaleSwitcherThemeWrapper({ locale }: LocaleAcceptorProps) {
return (
);
}
export function LocaleSwitcher({ locale }: LocaleAcceptorProps) {
return (
{
localStorage.setItem("preferred-locale", locale);
let rawPath = window.location.pathname;
for (const supported of locales.supported) {
if (window.location.pathname.startsWith(`/${supported.locale}`)) {
rawPath = rawPath.replace(`/${supported.locale}`, "");
break;
}
}
window.location.pathname = `${
locale === locales.default ? "" : `/${locale}`
}${rawPath}`;
}}
>
{locales.supported.map(({ locale }) => (
{SUPPORTED_LOCALE_FLAGS[locale]}{" "}
{
STRINGS[locale].common.locales[
locale as keyof BlitzKitStrings["common"]["locales"]
]
}
))}
);
}