A compact "HU | EN" switcher next to the theme toggle (desktop) and the menu button (mobile). Each link opens the current page in the other language with its translated slug (/hu/szolgaltatasok <-> /en/services), unknown pages fall back to the language's home. English is always offered (user decision), even before a page's English is approved. Links carry lang/hrefLang, the active one aria-current, and the group a localized accessible name. No flags: a flag marks a country, not a language. Unit and component tests plus staging smoke SMOKE-08. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
'use client'
|
|
|
|
import { Fragment } from 'react'
|
|
import Link from 'next/link'
|
|
import { usePathname } from 'next/navigation'
|
|
import { LOCALE_NAMES, languageLinks } from '@/lib/i18n'
|
|
|
|
/**
|
|
* MITHOME-115: compact "HU | EN" switcher. Each link keeps the current page
|
|
* in the other language (translated slug, src/lib/i18n.ts languageLinks).
|
|
*
|
|
* DECISION (user): English is always offered, even before a page's English
|
|
* translation is approved — the page then shows Hungarian text (MITHOME-113
|
|
* gate). No flags: a flag marks a country, not a language.
|
|
* WHY `lang`/`hrefLang` on the links: screen readers pronounce "English"
|
|
* correctly on a Hungarian page (WCAG 3.1.2).
|
|
*/
|
|
export function LanguageSwitcher({ label }: { label: string }) {
|
|
const links = languageLinks(usePathname() ?? '/')
|
|
|
|
return (
|
|
<div role="group" aria-label={label} className="flex items-center text-sm">
|
|
{links.map((link, index) => (
|
|
<Fragment key={link.locale}>
|
|
{index > 0 && (
|
|
<span aria-hidden="true" style={{ color: 'var(--color-border)' }}>
|
|
|
|
|
</span>
|
|
)}
|
|
<Link
|
|
href={link.href}
|
|
hrefLang={link.locale}
|
|
lang={link.locale}
|
|
aria-label={LOCALE_NAMES[link.locale].name}
|
|
aria-current={link.isActive ? 'true' : undefined}
|
|
className="px-1.5 py-1 rounded transition-colors duration-200 hover-scale"
|
|
style={{
|
|
color: link.isActive ? 'var(--color-primary-600)' : 'var(--color-foreground-muted)',
|
|
fontWeight: link.isActive ? 700 : 500,
|
|
}}
|
|
>
|
|
{LOCALE_NAMES[link.locale].code}
|
|
</Link>
|
|
</Fragment>
|
|
))}
|
|
</div>
|
|
)
|
|
}
|