added language switcher

This commit is contained in:
2024-02-17 08:32:53 +01:00
parent 4f6d31a7c1
commit 1c66940287
6 changed files with 47 additions and 15 deletions

16
app/ui/SelectLanguage.tsx Normal file
View File

@@ -0,0 +1,16 @@
"use client";
import { useLocale } from "next-intl";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { defaultLocale, localeNames, locales } from "../i18n";
export const SelectLanguage: React.FC = () => {
const currentPathname = usePathname();
const locale = useLocale();
const secondLocale = locales.find((l) => l !== locale) as string;
const secondLocalePathname = defaultLocale === locale ? `/${secondLocale}${currentPathname}` : currentPathname.replace(`/${locale}/`, `/${secondLocale}/`);
return (<Link className="btn btn-ghost text-xl self-end" href={secondLocalePathname}>{localeNames[secondLocale]}</Link>);
}