Honest baseline after removing 45 gaming suppressions. Structural: lib/game plus root hooks extraction, CORS origin echo, DEV_ORIGINS layering. Fixes: error-cause binding, discord 5xx split, null-cache guard, co-located tests, rejecting-fetch coverage, naming and typing cleanup, socket controller, cache bound, cascade helpers, latch resets. Hardening: per-IP rate limit on API routes, deterministic-miss UX, retry cooldown plus cap. Suite 140 green, build plus lint clean.
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { LOCALES, LOCALE_LABELS, LOCALE_COOKIE, type Locale } from "@/lib/i18n/locales";
|
|
|
|
function writeLocaleCookie(locale: Locale): void {
|
|
document.cookie = `${LOCALE_COOKIE}=${locale}; path=/; max-age=31536000; SameSite=Lax`;
|
|
}
|
|
|
|
export function LanguageSwitcher({ current }: { current: Locale }) {
|
|
function switchTo(locale: Locale) {
|
|
if (locale === current) {
|
|
return;
|
|
}
|
|
writeLocaleCookie(locale);
|
|
window.location.reload();
|
|
}
|
|
|
|
return (
|
|
<div
|
|
role="group"
|
|
aria-label="language"
|
|
className="flex items-center gap-1 rounded-full border border-white/10 bg-white/5 p-1"
|
|
>
|
|
{LOCALES.map((locale) => (
|
|
<button
|
|
key={locale}
|
|
type="button"
|
|
onClick={() => switchTo(locale)}
|
|
aria-pressed={locale === current}
|
|
className={`cursor-pointer rounded-full px-2.5 py-1 font-mono text-xs transition-colors ${
|
|
locale === current
|
|
? "bg-blurple text-white"
|
|
: "text-zinc-400 hover:text-white"
|
|
}`}
|
|
>
|
|
{LOCALE_LABELS[locale]}
|
|
</button>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|