feat: add runtime language selector in header (EN/FR toggle)

- Add LanguageSelector component with globe icon + cycle button
- Refactor i18n to support reactive locale switching via useSyncExternalStore
- Locale priority: localStorage > VITE_LOCALE > navigator.language > 'en'
- All components now use useT() hook for reactive re-rendering on locale change
- Persists choice to localStorage (key: pinchchat-locale)
- No page reload needed — instant switch
This commit is contained in:
Nicolas Varrot
2026-02-11 16:18:22 +00:00
parent b6a989bb51
commit 9b3aed4adc
12 changed files with 155 additions and 29 deletions

View File

@@ -0,0 +1,24 @@
import { Globe } from 'lucide-react';
import { setLocale, supportedLocales, localeLabels } from '../lib/i18n';
import { useLocale } from '../hooks/useLocale';
export function LanguageSelector() {
const current = useLocale();
const cycle = () => {
const idx = supportedLocales.indexOf(current);
const next = supportedLocales[(idx + 1) % supportedLocales.length];
setLocale(next);
};
return (
<button
onClick={cycle}
className="flex items-center gap-1.5 rounded-2xl border border-white/8 bg-zinc-800/30 px-2.5 py-1.5 text-xs text-zinc-400 hover:text-zinc-200 hover:bg-white/5 transition-colors"
title="Change language"
>
<Globe size={14} />
<span className="font-medium">{localeLabels[current] || current.toUpperCase()}</span>
</button>
);
}