feat(web): HU | EN language switcher in the header (MITHOME-115)

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>
This commit is contained in:
Do Siki
2026-09-29 12:22:11 +02:00
co-authored by Claude Opus 5.5
parent 8687ae28a2
commit 2bb9f122d5
9 changed files with 184 additions and 4 deletions
+32
View File
@@ -50,3 +50,35 @@ export function switchLocalePath(currentLocale: Locale, targetLocale: Locale, sl
const key = resolvePageKey(currentLocale, slug)
return localePath(targetLocale, key)
}
/**
* MITHOME-115: nyelvnevek a nyelvválasztóhoz. WHY statikus és nem Payload-
* tartalom: a nyelv kódja és saját nyelvű neve (endonim) nem fordítandó
* szöveg — ugyanaz minden nyelvű oldalon.
*/
export const LOCALE_NAMES: Record<Locale, { code: string; name: string }> = {
hu: { code: 'HU', name: 'Magyar' },
en: { code: 'EN', name: 'English' },
}
/** A böngésző útvonalából a nyelv és a szlög (`/hu/rolunk` → hu, rolunk). */
export function parseLocalePath(pathname: string): { locale: Locale; slug?: string } {
const [first, second] = pathname.split('/').filter(Boolean)
return first && isLocale(first) ? { locale: first, slug: second } : { locale: DEFAULT_LOCALE }
}
export type LanguageLink = { locale: Locale; href: string; isActive: boolean }
/**
* MITHOME-115: a nyelvválasztó linkjei — minden nyelvre ugyanaz az oldal a
* lefordított szlöggel (/hu/szolgaltatasok ↔ /en/services); ismeretlen
* oldalnál az adott nyelv főoldala.
*/
export function languageLinks(pathname: string): LanguageLink[] {
const { locale, slug } = parseLocalePath(pathname)
return LOCALES.map((target) => ({
locale: target,
href: switchLocalePath(locale, target, slug),
isActive: target === locale,
}))
}