[dyad] Added language switcher - wrote 10 file(s), renamed 2 file(s), added next-intl package(s)
This commit is contained in:
34
src/components/language-switcher.tsx
Normal file
34
src/components/language-switcher.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
"use client";
|
||||
|
||||
import { useLocale, useTranslations } from "next-intl";
|
||||
import { useRouter, usePathname } from "next-intl/client";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
|
||||
export function LanguageSwitcher() {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const locale = useLocale();
|
||||
const t = useTranslations("LanguageSwitcher");
|
||||
|
||||
const onSelectChange = (value: string) => {
|
||||
router.replace(pathname, { locale: value });
|
||||
};
|
||||
|
||||
return (
|
||||
<Select defaultValue={locale} onValueChange={onSelectChange}>
|
||||
<SelectTrigger className="w-[120px]">
|
||||
<SelectValue placeholder={t("placeholder")} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="en">English</SelectItem>
|
||||
<SelectItem value="es">Español</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user