feat: replace emoji flags with SVG flag images in LanguageSwitcher
This commit is contained in:
@@ -4,11 +4,11 @@ import { useLocale } from 'next-intl'
|
|||||||
import { useRouter, usePathname } from '@/navigation'
|
import { useRouter, usePathname } from '@/navigation'
|
||||||
import { routing } from '@/i18n/routing'
|
import { routing } from '@/i18n/routing'
|
||||||
|
|
||||||
const FLAGS: Record<string, string> = {
|
const FLAG_LABELS: Record<string, string> = {
|
||||||
en: '🇺🇸',
|
en: 'English',
|
||||||
fr: '🇫🇷',
|
fr: 'Français',
|
||||||
es: '🇪🇸',
|
es: 'Español',
|
||||||
it: '🇮🇹',
|
it: 'Italiano',
|
||||||
}
|
}
|
||||||
|
|
||||||
export function LanguageSwitcher() {
|
export function LanguageSwitcher() {
|
||||||
@@ -17,21 +17,26 @@ export function LanguageSwitcher() {
|
|||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ display: 'flex', gap: '0.5rem', padding: '0.5rem 2rem' }}>
|
<div className="flex items-center gap-1">
|
||||||
{routing.locales.map((loc) => (
|
{routing.locales.map((loc) => (
|
||||||
<button
|
<button
|
||||||
key={loc}
|
key={loc}
|
||||||
onClick={() => router.replace(pathname, { locale: loc })}
|
onClick={() => router.replace(pathname, { locale: loc })}
|
||||||
aria-label={loc}
|
aria-label={FLAG_LABELS[loc]}
|
||||||
style={{
|
className={[
|
||||||
fontSize: '1.5rem',
|
'rounded transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-violet-500',
|
||||||
background: 'none',
|
loc === locale
|
||||||
border: 'none',
|
? 'opacity-100 ring-2 ring-violet-500 ring-offset-1 ring-offset-white dark:ring-offset-slate-950'
|
||||||
cursor: 'pointer',
|
: 'opacity-40 hover:opacity-70',
|
||||||
opacity: loc === locale ? 1 : 0.4,
|
].join(' ')}
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{FLAGS[loc]}
|
<img
|
||||||
|
src={`/flags/${loc}.svg`}
|
||||||
|
alt={FLAG_LABELS[loc]}
|
||||||
|
width={28}
|
||||||
|
height={20}
|
||||||
|
className="rounded-sm block"
|
||||||
|
/>
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user