Build and Deploy / test-backend (push) Successful in 1m11s
Build and Deploy / lint-frontend (push) Successful in 21s
Build and Deploy / build-backend (push) Successful in 58s
Build and Deploy / deploy (push) Canceled after 0s
Build and Deploy / build-frontend (push) Canceled after 5m38s
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
"use client";
|
|
|
|
import { useRouter } from "next/navigation";
|
|
import { useLocale, useTranslations } from "next-intl";
|
|
import { LanguagesIcon } from "lucide-react";
|
|
import { setLocale } from "@/app/actions/setLocale";
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu";
|
|
import { LANGUAGE_CODES } from "@/types/api";
|
|
|
|
export function LocaleSwitcher() {
|
|
const locale = useLocale();
|
|
const t = useTranslations("Locale");
|
|
const router = useRouter();
|
|
|
|
const handleChange = async (next: string) => {
|
|
if (next === locale) return;
|
|
await setLocale(next);
|
|
router.refresh();
|
|
};
|
|
|
|
return (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger
|
|
render={
|
|
<Button variant="outline" size="icon" aria-label={t("switch")}>
|
|
<LanguagesIcon />
|
|
</Button>
|
|
}
|
|
/>
|
|
<DropdownMenuContent align="end">
|
|
{LANGUAGE_CODES.map((code) => (
|
|
<DropdownMenuItem key={code} onClick={() => handleChange(code)}>
|
|
{t(code)}
|
|
</DropdownMenuItem>
|
|
))}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
);
|
|
}
|