import { useTranslation } from 'react-i18next'; import { Languages } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuCheck, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { changeLanguage, LANGUAGE_LABELS, SUPPORTED_LANGUAGES, type SupportedLanguage, } from '@/i18n/config'; /** Language selector for the topbar; lazy-loads the chosen locale (Q4-B). */ export function LanguageSwitcher() { const { t, i18n } = useTranslation(); // Use i18n.language (set synchronously on change) rather than resolvedLanguage // (which can lag when bundles were lazy-loaded). Split on '-' to normalise // region variants like 'nl-NL' → 'nl'. const rawLang = i18n.language?.split('-')[0] ?? 'en'; const current = (SUPPORTED_LANGUAGES.includes(rawLang as SupportedLanguage) ? rawLang : 'en') as SupportedLanguage; return ( {t('userMenu.language')} {SUPPORTED_LANGUAGES.map((lng) => ( { void changeLanguage(lng); }} data-testid={`language-option-${lng}`} > {LANGUAGE_LABELS[lng]} ))} ); }