import { useState } from "react"; import { t } from "../../lib/i18n"; const LOCALE_STORAGE_KEY = "locale"; const SUPPORTED_LOCALES = ["ko", "en"] as const; type Locale = (typeof SUPPORTED_LOCALES)[number]; function resolveLocale(): Locale { if (typeof window === "undefined") { return "ko"; } const stored = window.localStorage.getItem(LOCALE_STORAGE_KEY); if (stored === "ko" || stored === "en") { return stored; } const pathLocale = window.location.pathname.split("/")[1]; if (pathLocale === "ko" || pathLocale === "en") { return pathLocale; } const browserLang = window.navigator.language.toLowerCase(); return browserLang.startsWith("ko") ? "ko" : "en"; } function LanguageSelector() { const [locale, setLocale] = useState(resolveLocale()); const handleChange = (next: Locale) => { if (next === locale) { return; } window.localStorage.setItem(LOCALE_STORAGE_KEY, next); setLocale(next); window.location.reload(); }; return ( ); } export default LanguageSelector;