'use client';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { getLocaleFromPath, getLocalizedPath, t, type Locale } from '@/lib/i18n';
export function LocaleSwitcher() {
const pathname = usePathname();
const currentLocale = getLocaleFromPath(pathname);
const locales: Locale[] = ['en', 'de'];
return (
{locales.map((locale) => {
const isActive = currentLocale === locale;
const label = locale === 'en' ? 'English' : 'Deutsch';
const flag = locale === 'en' ? 'πΊπΈ' : 'π©πͺ';
// Get the current path without locale
const currentPath = pathname.replace(/^\/(de|en)/, '') || '/';
const href = getLocalizedPath(currentPath, locale);
return (
{flag}
{label}
);
})}
);
}