"use client"; import { useState } from "react"; import { useI18n } from "@/lib/i18n/client"; import { LOCALES, LOCALE_NAMES, type Locale } from "@/lib/i18n/config"; interface LanguageSwitcherProps { className?: string; /** "compact" = icon + short label, fits a header next to other icons. * "full" = icon + full label + chevron, for a settings panel row. */ variant?: "compact" | "full"; } // Locales with actual filled-in translations. The catalog ships stub files // for the other 18 locales (so the loader doesn't 404), but only these // three have been reviewed. Hide the rest until they're translated. const TRANSLATED_LOCALES: Locale[] = ["zh-CN", "en", "ja"]; // Short labels for the compact header button — keeps the row tidy next to // the gear/github/x icons where every other item is 1-2 glyphs. const SHORT_LOCALE_NAMES: Record = { "zh-CN": "中文", "zh-TW": "繁中", "zh-HK": "繁中", en: "EN", ja: "日本語", ko: "한국어", es: "ES", fr: "FR", de: "DE", "pt-BR": "PT", pt: "PT", ru: "RU", it: "IT", vi: "VI", th: "TH", id: "ID", tr: "TR", pl: "PL", nl: "NL", uk: "UK", hi: "हिन्दी", cs: "CZ", }; export function LanguageSwitcher({ className = "", variant = "full" }: LanguageSwitcherProps) { const { locale, setLocale, t } = useI18n(); const [isOpen, setIsOpen] = useState(false); const currentLocaleName = LOCALE_NAMES[locale] || locale; const currentShortName = SHORT_LOCALE_NAMES[locale] || locale; const availableLocales = LOCALES.filter((l) => TRANSLATED_LOCALES.includes(l)); return (
{isOpen && ( <>
setIsOpen(false)} aria-hidden="true" />
{availableLocales.map((loc) => ( ))}
)}
); }