mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-10-03 18:23:47 +10:00
* refactor to @base-ui/react * fix all * fixes to accordion * more updates * switch to chat/completions api from openai * update version to v5.0.12
35 lines
972 B
TypeScript
35 lines
972 B
TypeScript
import { i18n } from "@lingui/core";
|
|
import { useLingui } from "@lingui/react";
|
|
import { isLocale, type Locale, loadLocale, localeMap, setLocaleServerFn } from "@/utils/locale";
|
|
import { Combobox, type SingleComboboxProps } from "../ui/combobox";
|
|
|
|
type Props = Omit<SingleComboboxProps, "options" | "value" | "onValueChange">;
|
|
|
|
export const getLocaleOptions = () => {
|
|
return Object.entries(localeMap).map(([value, label]) => ({
|
|
value: value as Locale,
|
|
label: i18n.t(label),
|
|
keywords: [i18n.t(label)],
|
|
}));
|
|
};
|
|
|
|
export function LocaleCombobox(props: Props) {
|
|
const { i18n } = useLingui();
|
|
|
|
const onLocaleChange = async (value: string | null) => {
|
|
if (!value || !isLocale(value)) return;
|
|
await Promise.all([loadLocale(value), setLocaleServerFn({ data: value })]);
|
|
window.location.reload();
|
|
};
|
|
|
|
return (
|
|
<Combobox
|
|
showClear={false}
|
|
defaultValue={i18n.locale}
|
|
options={getLocaleOptions()}
|
|
onValueChange={onLocaleChange}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|