11---
22/**
3- * Dropdown language picker for the landing page.
3+ * Dropdown language picker for the landing page and CTA page .
44 * Uses a simple div-based menu (no ul/li) for maximum Safari compatibility.
55 * Client-side JS detects the browser language and promotes the match to the top.
6+ *
7+ * Props:
8+ * locale: current locale code (e.g. "en", "fr")
9+ * suffix: optional path suffix appended to each locale root
10+ * (e.g. "cta/" for CTA page so entries link to /{locale}/cta/).
11+ * For English ("en"), the root is "/" so "/cta/" is the result.
612 */
713import { languages } from ' ../i18n/config' ;
814
915interface Props {
1016 locale: string ;
17+ suffix? : string ;
1118}
1219
13- const { locale } = Astro .props ;
20+ const { locale, suffix = ' ' } = Astro .props ;
1421const currentLabel = languages [locale as keyof typeof languages ]?.label ?? ' English' ;
1522const entries = Object .entries (languages ) as [string , { label: string ; path: string }][];
23+
24+ // Build the URL for a given locale, honoring the suffix
25+ function localeHref(code : string , basePath : string ): string {
26+ if (! suffix ) return basePath ;
27+ // basePath is e.g. "/fr/" or "/en/" — just append the suffix
28+ return basePath + suffix ;
29+ }
1630---
1731
1832<div class =" lang-picker" data-current ={ locale } >
@@ -23,7 +37,7 @@ const entries = Object.entries(languages) as [string, { label: string; path: str
2337 </button >
2438 <div class =" lang-picker-menu" >
2539 { entries .map (([code , { label , path }]) => (
26- <a href = { path } data-lang = { code } class :list = { [' lang-picker-item' , code === locale && ' lang-current' ]} >
40+ <a href = { localeHref ( code , path ) } data-lang = { code } class :list = { [' lang-picker-item' , code === locale && ' lang-current' ]} >
2741 <span class = " lang-picker-item-label" >{ label } </span >
2842 { code === locale && <span class = " lang-picker-check" >✓ </span >}
2943 </a >
0 commit comments