"use client"; import { useLingui } from "@lingui/react/macro"; import { CheckIcon, ChevronDownIcon, GlobeIcon } from "lucide-react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { isLocalizedLandingPath, localizeLandingHref, parseLandingPathname, } from "@/utils/i18n/landing"; import { DEFAULT_LOCALE, LOCALE_LABELS, LOCALES, toLocale, } from "@/utils/i18n/locales"; import { cn } from "@/utils"; // Links to the current page in every language. Hidden on pages that have no // translations. export function LanguageSwitcher({ className }: { className?: string }) { const { t, i18n } = useLingui(); const pathname = usePathname(); const { path } = parseLandingPathname(pathname); // The English home page links to /home: next.config sends signed-in // visitors from "/" to the app, and /home shows them the same page. const translatedPath = path === "/home" ? "/" : path; if (!isLocalizedLandingPath(translatedPath)) return null; const englishHomeHref = i18n.locale === DEFAULT_LOCALE ? path : "/home"; const currentLocale = toLocale(i18n.locale); return ( {LOCALES.map((locale) => { const isCurrent = locale === currentLocale; return ( {LOCALE_LABELS[locale]} {isCurrent ? ( ); })} ); }