feat: restructure routes under [locale], add LanguageSwitcher

This commit is contained in:
2026-08-10 15:34:34 +02:00
parent 930b824902
commit a89095b5c4
7 changed files with 117 additions and 36 deletions
+39
View File
@@ -0,0 +1,39 @@
'use client'
import { useLocale } from 'next-intl'
import { useRouter, usePathname } from '@/navigation'
import { routing } from '@/i18n/routing'
const FLAGS: Record<string, string> = {
en: '🇺🇸',
fr: '🇫🇷',
es: '🇪🇸',
it: '🇮🇹',
}
export function LanguageSwitcher() {
const locale = useLocale()
const router = useRouter()
const pathname = usePathname()
return (
<div style={{ display: 'flex', gap: '0.5rem', padding: '0.5rem 2rem' }}>
{routing.locales.map((loc) => (
<button
key={loc}
onClick={() => router.replace(pathname, { locale: loc })}
aria-label={loc}
style={{
fontSize: '1.5rem',
background: 'none',
border: 'none',
cursor: 'pointer',
opacity: loc === locale ? 1 : 0.4,
}}
>
{FLAGS[loc]}
</button>
))}
</div>
)
}