TypeScript 93.3%
JavaScript 4.4%
CSS 2.3%
1/**2 * Author: Simon-Pierre Boucher3 * Contact: contact@spboucher.ai4 * Project: Hilmacorp.ai — Web Platform5 * File: components/LocaleSwitcher.tsx6 * Description: Client component toggling between FR and EN, preserving the current path7 */89"use client";1011import Link from "next/link";12import { usePathname } from "next/navigation";1314export default function LocaleSwitcher({15 locale,16 label,17}: {18 locale: "fr" | "en";19 label: string;20}) {21 const pathname = usePathname() ?? `/${locale}`;22 const target = locale === "fr" ? "en" : "fr";23 const switched = pathname.replace(new RegExp(`^/${locale}(?=/|$)`), `/${target}`);2425 return (26 <Link27 href={switched}28 onClick={() => {29 document.cookie = `NEXT_LOCALE=${target};path=/;max-age=31536000;samesite=lax`;30 }}31 className="rounded-full border border-line-strong px-3.5 py-1.5 font-mono text-xs uppercase tracking-widest text-ink-soft transition-colors hover:border-accent hover:text-accent"32 aria-label={label}33 >34 {label}35 </Link>36 );37}38