Files
slp-modular-cms/frontend/src/i18n/LanguageSwitcher.tsx
T
SluijsensandClaude Haiku 4.5 d69512a449 fix(i18n): eager-load nl bundle, fix language selector, remove hardcoded backend messages
- Eager-load both en and nl translation bundles at i18n init to eliminate
  the async gap that caused English flash when Dutch was the detected language
- LanguageSwitcher: use i18n.language (synchronous) instead of resolvedLanguage
  (asynchronous) so the visual selection is always correct after switching
- AvailabilityController: remove hardcoded English messages ("System is running
  normally.") from GET /availability/status; return empty string so the frontend
  translations control the display text

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-06-22 14:16:27 +02:00

62 lines
2.1 KiB
TypeScript

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 (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon"
aria-label={t('userMenu.language')}
data-testid="language-switcher-button"
>
<Languages />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>{t('userMenu.language')}</DropdownMenuLabel>
<DropdownMenuSeparator />
{SUPPORTED_LANGUAGES.map((lng) => (
<DropdownMenuItem
key={lng}
onSelect={() => {
void changeLanguage(lng);
}}
data-testid={`language-option-${lng}`}
>
{LANGUAGE_LABELS[lng]}
<DropdownMenuCheck checked={current === lng} />
</DropdownMenuItem>
))}
</DropdownMenuContent>
</DropdownMenu>
);
}