diff --git a/www/src/components/LanguageSwitcher.astro b/www/src/components/LanguageSwitcher.astro index e2a7116..9acdefa 100644 --- a/www/src/components/LanguageSwitcher.astro +++ b/www/src/components/LanguageSwitcher.astro @@ -18,14 +18,36 @@ for (const entry of posts) { const prefix = entry.data.lang === 'en' ? '' : `/${entry.data.lang}`; available.add(`${prefix}/library/${entry.data.slug}`); } + +const langMeta: Record = { + en: { short: 'EN', full: 'English' }, + es: { short: 'ES', full: 'Español' }, + ar: { short: 'ع', full: 'عربي' }, +}; + const choices = [ - { code: 'en', label: 'EN', href: bare }, - { code: 'es', label: 'ES', href: `/es${bare === '/' ? '' : bare}` }, - { code: 'ar', label: 'ع', href: `/ar${bare === '/' ? '' : bare}` } + { code: 'en', href: bare }, + { code: 'es', href: `/es${bare === '/' ? '' : bare}` }, + { code: 'ar', href: `/ar${bare === '/' ? '' : bare}` }, ].filter(({ href }) => available.has(href)); + +const activeCode = pathname.startsWith('/ar') ? 'ar' : pathname.startsWith('/es') ? 'es' : 'en'; +const activeShort = langMeta[activeCode]?.short ?? 'EN'; --- -