Repository Public
1"use client";2import { usePathname } from "next/navigation";3import type { Locale } from "@/lib/i18n";45/** Bascule fr/en vers la même page dans l'autre langue (navigation complète : l'attribut lang du document change). */6export function LangSwitch({ locale, label, title }: { locale: Locale; label: string; title: string }) {7 const pathname = usePathname() ?? "/";8 const bare = pathname.replace(/^\/(fr|en)(?=\/|$)/, "") || "/";9 const target = locale === "fr" ? (bare === "/" ? "/en" : `/en${bare}`) : bare;10 return (11 <a href={target} hrefLang={locale === "fr" ? "en" : "fr"} lang={locale === "fr" ? "en" : "fr"} aria-label={title} data-testid="lang-switch"12 // La recherche en cours (`?q=`, `?v=`) suit la bascule : lue au clic, pour ne pas dépendre du rendu.13 onClick={(e) => { if (window.location.search) { e.preventDefault(); window.location.assign(target + window.location.search); } }}14 className="inline-flex min-h-11 min-w-11 items-center justify-center gap-1.5 rounded-full border border-line bg-surface px-3.5 text-sm font-medium text-ink transition-colors hover:bg-surface-2">15 <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" aria-hidden="true" className="text-muted"><circle cx="12" cy="12" r="8.5" /><path d="M3.5 12h17M12 3.5c2.6 2.4 2.6 14.6 0 17M12 3.5c-2.6 2.4-2.6 14.6 0 17" /></svg>16 <span className="sm:hidden">{locale === "fr" ? "EN" : "FR"}</span>17 <span className="hidden sm:inline">{label}</span>18 </a>19 );20}21