[dyad] Added language switcher for English and German - wrote 10 file(s), renamed 2 file(s), added next-intl package(s)

This commit is contained in:
[dyad]
2026-01-18 12:39:47 +01:00
parent 1d41f871ee
commit 2136a2dd79
11 changed files with 799 additions and 118 deletions

View File

@@ -0,0 +1,35 @@
"use client";
import { useLocale } from "next-intl";
import { useRouter, usePathname } from "next-intl/client";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { useTranslations } from "next-intl";
export function LanguageSwitcher() {
const t = useTranslations("LanguageSwitcher");
const locale = useLocale();
const router = useRouter();
const pathname = usePathname();
const onSelectChange = (value: string) => {
router.replace(pathname, { locale: value });
};
return (
<Select onValueChange={onSelectChange} defaultValue={locale}>
<SelectTrigger className="w-[120px]">
<SelectValue placeholder={t("placeholder")} />
</SelectTrigger>
<SelectContent>
<SelectItem value="en">{t("en")}</SelectItem>
<SelectItem value="de">{t("de")}</SelectItem>
</SelectContent>
</Select>
);
}