Files
websitedev/proto/src/lib/i18n.ts
T
Do SikiandClaude Opus 5.5 1e0742a548
CI Pipeline with Test Management / 🧪 Run Tests & Generate Reports (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 🧪 Run Tests & Generate Reports (push) Canceled after 0s
CI Pipeline with Test Management / 🐳 Docker Integration Tests (push) Canceled after 0s
CI Pipeline with Test Management / 🏗️ Build Docker Image (push) Canceled after 0s
CI Pipeline with Test Management / 📊 Generate Test Summary (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 📊 Analyze Test Coverage (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 🔄 Sync with Linear (push) Canceled after 0s
Test Reporting & Gherkin Analysis / ⚡ Performance Monitoring (push) Canceled after 0s
feat(cms): hosting plans page with lifecycle gate and net + VAT prices (MITHOME-130)
- Products collection (interim mirror of the PLATFM-14 catalogue contract):
  lifecycle status, product type, required whole-forint net price, yearly
  billing, service definition, per-product English gate
- HostingPlans global: page copy, comparison labels, VAT rate (27%)
- Gate: production shows only active plans, staging all but retired; with no
  showable plan the page is 404 and left out of the menu and the sitemap
- /hu/tarhely-csomagok <-> /en/hosting-plans via PAGE_SLUGS (hreflang,
  language switcher, CTA page picker)
- Seed migration 20260929_hosting_plans: mIT Start (14 900 Ft/yr, 5 mailboxes)
  and mIT Mid (23 900 Ft/yr) as drafts, English AI draft; idempotent
- Production SEO suite expects at least 12 sitemap URLs; new SMOKE-10

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 19:36:44 +02:00

87 lines
3.5 KiB
TypeScript

/**
* MITHOME-91/114: locale + útvonal segédfüggvények.
*
* URL-stratégia (2026-09-10, felülírja a korábbi "hu prefix nélkül" döntést):
* mindkét nyelv prefixet kap, szimmetrikusan (`/hu/...`, `/en/...`), a
* szlögök nyelvenként lefordítva (pl. /hu/rolunk vs /en/about). Nincs
* redirect a régi, prefix nélküli URL-ekről — a projekt még nincs
* production-ben (MITHOME-15 backlog).
*/
export const LOCALES = ['hu', 'en'] as const
export type Locale = (typeof LOCALES)[number]
export const DEFAULT_LOCALE: Locale = 'hu'
export function isLocale(value: string): value is Locale {
return (LOCALES as readonly string[]).includes(value)
}
/** A catch-all [slug] route alá tartozó oldalak azonosítói. */
export type PageKey = 'about' | 'services' | 'hostingPlans' | 'contact' | 'privacy' | 'terms'
/** Nyelvenkénti szlög minden oldalhoz — a nyelvváltó (MITHOME-115) és a
* sitemap/hreflang (MITHOME-116) is ezt a táblát fogja használni. */
export const PAGE_SLUGS: Record<PageKey, Record<Locale, string>> = {
about: { hu: 'rolunk', en: 'about' },
services: { hu: 'szolgaltatasok', en: 'services' },
// MITHOME-130: only reachable while a showable plan exists (src/lib/products.ts).
hostingPlans: { hu: 'tarhely-csomagok', en: 'hosting-plans' },
contact: { hu: 'kapcsolat', en: 'contact' },
privacy: { hu: 'adatvedelem', en: 'privacy-policy' },
terms: { hu: 'felhasznalasi-feltetelek', en: 'terms-of-service' },
}
/** slug -> PageKey visszakeresés egy adott nyelven belül. */
export function resolvePageKey(locale: Locale, slug: string): PageKey | undefined {
return (Object.keys(PAGE_SLUGS) as PageKey[]).find((key) => PAGE_SLUGS[key][locale] === slug)
}
/** Útvonal a főoldalhoz vagy egy PageKey-hez, adott nyelven. */
export function localePath(locale: Locale, key?: PageKey): string {
if (!key) return `/${locale}`
return `/${locale}/${PAGE_SLUGS[key][locale]}`
}
/**
* Ugyanaz az oldal a másik nyelven — a nyelvváltóhoz (MITHOME-115).
* Ha a jelenlegi útvonal nem ismert PageKey (pl. 404), a másik nyelv
* főoldalára esik vissza.
*/
export function switchLocalePath(currentLocale: Locale, targetLocale: Locale, slug?: string): string {
if (!slug) return localePath(targetLocale)
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,
}))
}