disclosure-bureau/web/components/locale-toggle-client.tsx

60 lines
2.1 KiB
TypeScript
Raw Normal View History

"use client";
import { useRouter } from "next/navigation";
import { Globe } from "lucide-react";
import type { Locale } from "./locale-toggle";
W5.8: language toggle in the navbar (whole-site PT-BR / EN) User: "quero que o usuário possa escolher o idioma na navbar, e então leia o site todo em seu idioma." The locale infrastructure already existed (cookie + getLocale() + every page renders bilingual). The toggle only lived as a subtle floating control bottom-left. This surfaces it in the navbars where users expect it, and confirms whole-site language switching. locale-toggle-client.tsx - New variant="navbar": gold-amber pill matching the magazine theme (PT | EN, active = solid gold). Retro green variant kept for the floating fallback. - Guard: clicking the already-active language is a no-op. - aria-pressed on each button for a11y. locale-toggle.tsx: LocaleToggle gains variant passthrough. site-header.tsx: <LocaleToggle variant="navbar"> added to the main nav (homepage + /sightings /witnesses /objects /locations /operations /documents). bureau-nav.tsx: optional `locale` prop renders the same toggle pushed to the right (ml-auto) on /bureau, /c/[slug], /h/[id], /jobs/[id]. All four callers now pass locale (getLocale added to h + jobs pages). Cookie-based: switching sets `locale` cookie + router.refresh(); the server re-renders every component through getLocale(), so the entire page — headers, hero, summaries, case narratives, entity cards — flips language in one click. The floating bottom-left toggle stays as a global fallback for pages without a navbar (/d, /e, /search, /graph). Also this session: Sun-Tzu smoke succeeded on the refreshed CLAUDE_CODE_OAUTH_TOKEN — brief B-0001 written for the green fireballs ("bolas de fogo verdes confinadas ao corredor nuclear... cor espectral e trajetória quase horizontal que os próprios analistas consideraram irreconciliáveis com meteoros naturais", 3 pillars). Bulk entity enrichment resumed in the background. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 01:54:37 +00:00
export function LocaleToggleClient({
current,
variant = "retro",
}: { current: Locale; variant?: "retro" | "navbar" }) {
const router = useRouter();
function setLocale(next: Locale) {
W5.8: language toggle in the navbar (whole-site PT-BR / EN) User: "quero que o usuário possa escolher o idioma na navbar, e então leia o site todo em seu idioma." The locale infrastructure already existed (cookie + getLocale() + every page renders bilingual). The toggle only lived as a subtle floating control bottom-left. This surfaces it in the navbars where users expect it, and confirms whole-site language switching. locale-toggle-client.tsx - New variant="navbar": gold-amber pill matching the magazine theme (PT | EN, active = solid gold). Retro green variant kept for the floating fallback. - Guard: clicking the already-active language is a no-op. - aria-pressed on each button for a11y. locale-toggle.tsx: LocaleToggle gains variant passthrough. site-header.tsx: <LocaleToggle variant="navbar"> added to the main nav (homepage + /sightings /witnesses /objects /locations /operations /documents). bureau-nav.tsx: optional `locale` prop renders the same toggle pushed to the right (ml-auto) on /bureau, /c/[slug], /h/[id], /jobs/[id]. All four callers now pass locale (getLocale added to h + jobs pages). Cookie-based: switching sets `locale` cookie + router.refresh(); the server re-renders every component through getLocale(), so the entire page — headers, hero, summaries, case narratives, entity cards — flips language in one click. The floating bottom-left toggle stays as a global fallback for pages without a navbar (/d, /e, /search, /graph). Also this session: Sun-Tzu smoke succeeded on the refreshed CLAUDE_CODE_OAUTH_TOKEN — brief B-0001 written for the green fireballs ("bolas de fogo verdes confinadas ao corredor nuclear... cor espectral e trajetória quase horizontal que os próprios analistas consideraram irreconciliáveis com meteoros naturais", 3 pillars). Bulk entity enrichment resumed in the background. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 01:54:37 +00:00
if (next === current) return;
document.cookie = `locale=${next}; path=/; max-age=${60 * 60 * 24 * 365}; SameSite=Lax`;
router.refresh();
}
W5.8: language toggle in the navbar (whole-site PT-BR / EN) User: "quero que o usuário possa escolher o idioma na navbar, e então leia o site todo em seu idioma." The locale infrastructure already existed (cookie + getLocale() + every page renders bilingual). The toggle only lived as a subtle floating control bottom-left. This surfaces it in the navbars where users expect it, and confirms whole-site language switching. locale-toggle-client.tsx - New variant="navbar": gold-amber pill matching the magazine theme (PT | EN, active = solid gold). Retro green variant kept for the floating fallback. - Guard: clicking the already-active language is a no-op. - aria-pressed on each button for a11y. locale-toggle.tsx: LocaleToggle gains variant passthrough. site-header.tsx: <LocaleToggle variant="navbar"> added to the main nav (homepage + /sightings /witnesses /objects /locations /operations /documents). bureau-nav.tsx: optional `locale` prop renders the same toggle pushed to the right (ml-auto) on /bureau, /c/[slug], /h/[id], /jobs/[id]. All four callers now pass locale (getLocale added to h + jobs pages). Cookie-based: switching sets `locale` cookie + router.refresh(); the server re-renders every component through getLocale(), so the entire page — headers, hero, summaries, case narratives, entity cards — flips language in one click. The floating bottom-left toggle stays as a global fallback for pages without a navbar (/d, /e, /search, /graph). Also this session: Sun-Tzu smoke succeeded on the refreshed CLAUDE_CODE_OAUTH_TOKEN — brief B-0001 written for the green fireballs ("bolas de fogo verdes confinadas ao corredor nuclear... cor espectral e trajetória quase horizontal que os próprios analistas consideraram irreconciliáveis com meteoros naturais", 3 pillars). Bulk entity enrichment resumed in the background. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 01:54:37 +00:00
if (variant === "navbar") {
// Gold-amber magazine theme to match SiteHeader / BureauNav.
return (
<div className="inline-flex items-center gap-0.5 font-mono text-[11px] uppercase tracking-wider border border-[rgba(224,192,128,0.30)] rounded-full overflow-hidden">
<span className="pl-2.5 pr-1 text-[#5a6678]"><Globe size={11} /></span>
<button
onClick={() => setLocale("pt-br")}
aria-pressed={current === "pt-br"}
className={`px-2 py-1 transition-colors ${current === "pt-br" ? "bg-[#e0c080] text-[#0a0e1a] font-semibold" : "text-[#9aa6b8] hover:text-[#e0c080]"}`}
>
PT
</button>
<button
onClick={() => setLocale("en")}
aria-pressed={current === "en"}
className={`px-2 py-1 transition-colors ${current === "en" ? "bg-[#e0c080] text-[#0a0e1a] font-semibold" : "text-[#9aa6b8] hover:text-[#e0c080]"}`}
>
EN
</button>
</div>
);
}
return (
<div className="inline-flex items-center gap-1 font-mono text-[10px] uppercase tracking-widest border border-[rgba(0,255,156,0.32)] rounded">
<span className="px-2 py-1 text-[#5a6678]"><Globe size={11} /></span>
<button
onClick={() => setLocale("en")}
className={`px-2 py-1 ${current === "en" ? "bg-[rgba(0,255,156,0.12)] text-[#00ff9c]" : "text-[#8896aa] hover:text-[#7fdbff]"}`}
>
EN
</button>
<button
onClick={() => setLocale("pt-br")}
className={`px-2 py-1 ${current === "pt-br" ? "bg-[rgba(0,255,156,0.12)] text-[#00ff9c]" : "text-[#8896aa] hover:text-[#7fdbff]"}`}
>
PT-BR
</button>
</div>
);
}