From 2bb9f122d593c70655176008ada00eff9d03b7a9 Mon Sep 17 00:00:00 2001 From: Do Siki Date: Tue, 29 Sep 2026 12:22:11 +0200 Subject: [PATCH] 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 --- proto/e2e/staging-smoke.spec.ts | 10 ++++ proto/src/app/(frontend)/[locale]/layout.tsx | 3 +- proto/src/components/Header.test.tsx | 1 + proto/src/components/Header.tsx | 11 +++-- .../src/components/LanguageSwitcher.test.tsx | 39 +++++++++++++++ proto/src/components/LanguageSwitcher.tsx | 48 +++++++++++++++++++ proto/src/config/site.ts | 10 ++++ proto/src/lib/i18n.test.ts | 34 +++++++++++++ proto/src/lib/i18n.ts | 32 +++++++++++++ 9 files changed, 184 insertions(+), 4 deletions(-) create mode 100644 proto/src/components/LanguageSwitcher.test.tsx create mode 100644 proto/src/components/LanguageSwitcher.tsx create mode 100644 proto/src/lib/i18n.test.ts diff --git a/proto/e2e/staging-smoke.spec.ts b/proto/e2e/staging-smoke.spec.ts index a480b82..dca5a02 100644 --- a/proto/e2e/staging-smoke.spec.ts +++ b/proto/e2e/staging-smoke.spec.ts @@ -75,6 +75,16 @@ test('SMOKE-07: external links on the homepage open in a new tab', async ({ page } }) +// MITHOME-115: the language switcher keeps the current page (translated slug). +test('SMOKE-08: language switcher opens the same page in the other language', async ({ page }) => { + await page.goto('/hu/szolgaltatasok') + const english = page.getByRole('group', { name: 'Nyelv kiválasztása' }).first().getByRole('link', { name: 'English' }) + await expect(english).toHaveAttribute('href', '/en/services') + await english.click() + await expect(page).toHaveURL(/\/en\/services$/) + await expect(page.getByRole('group', { name: 'Choose language' }).first().getByRole('link', { name: 'Magyar' })).toHaveAttribute('href', '/hu/szolgaltatasok') +}) + test('SMOKE-05: empty contact form is blocked client-side without API submission', async ({ page }) => { let contactPostCount = 0 page.on('request', request => { diff --git a/proto/src/app/(frontend)/[locale]/layout.tsx b/proto/src/app/(frontend)/[locale]/layout.tsx index b5da35d..ab906ef 100644 --- a/proto/src/app/(frontend)/[locale]/layout.tsx +++ b/proto/src/app/(frontend)/[locale]/layout.tsx @@ -3,7 +3,7 @@ import Header from '../../../components/Header' import Footer from '../../../components/Footer' import { isLocale, localePath, type Locale } from '@/lib/i18n' import { getCommonContent, getHomeContent } from '@/lib/payload-content' -import { siteConfig, getMainNavigation, getFooterNavigation, getFooterLegalLinks, getSiteDescription } from '@/config/site' +import { siteConfig, getMainNavigation, getFooterNavigation, getFooterLegalLinks, getSiteDescription, getLanguageSwitcherLabel } from '@/config/site' // WHY force-dynamic (MITHOME-97): ezek az oldalak a Payload Local API-t hívják // (élő MongoDB-olvasás). generateStaticParams + SSG mellett a build időben @@ -43,6 +43,7 @@ export default async function LocaleLayout({ nav={getMainNavigation(locale)} homeHref={localePath(locale)} a11y={common.a11y} + languageLabel={getLanguageSwitcherLabel(locale)} />
{children} diff --git a/proto/src/components/Header.test.tsx b/proto/src/components/Header.test.tsx index bdbf2d0..64f379f 100755 --- a/proto/src/components/Header.test.tsx +++ b/proto/src/components/Header.test.tsx @@ -19,6 +19,7 @@ const headerProps = { nav: getMainNavigation('hu'), homeHref: '/hu', a11y: common.a11y, + languageLabel: 'Nyelv kiválasztása', } describe('Header', () => { diff --git a/proto/src/components/Header.tsx b/proto/src/components/Header.tsx index 454d77e..7f14fe6 100755 --- a/proto/src/components/Header.tsx +++ b/proto/src/components/Header.tsx @@ -7,14 +7,17 @@ import Link from 'next/link' import Image from 'next/image' import type { NavigationItem } from '@/types/site' import { externalLinkProps, isExternalHref } from '@/lib/external-link' +import { LanguageSwitcher } from './LanguageSwitcher' type HeaderProps = { nav: NavigationItem[] homeHref: string a11y: { openMenu: string; closeMenu: string } + /** MITHOME-115: accessible name of the language switcher group. */ + languageLabel: string } -export default function Header({ nav, homeHref, a11y }: HeaderProps) { +export default function Header({ nav, homeHref, a11y, languageLabel }: HeaderProps) { const [isMenuOpen, setIsMenuOpen] = useState(false) const [isScrolled, setIsScrolled] = useState(false) @@ -102,14 +105,16 @@ export default function Header({ nav, homeHref, a11y }: HeaderProps) { ))} - {/* Theme Toggle */} -
+ {/* Language switcher + Theme Toggle */} +
+
{/* Mobile menu button */}
+