--- import tPage from '$i18n/translations/components/languageLinks'; import tSite from '$i18n/translations/site'; import translate from '$i18n/translate'; import type Locale from '$types/Locale'; import getLocaleFromPath from '$lib/getLocaleFromPath'; // This logic assumes that there are exactly two locales. const currentLocale = getLocaleFromPath(Astro.url.pathname); const otherLocale: Locale = currentLocale === 'sco' ? 'en-GB' : 'sco'; const currentPath = Astro.url.pathname; const currentLocaleInPath = new RegExp(`(?<=^/)(${currentLocale}/)?`); const newsCurrentLocaleInPath = new RegExp(`(?<=/news/)(${currentLocale.toLocaleLowerCase()})`); const otherLocalePath = currentPath .replace(currentLocaleInPath, `${otherLocale}/`) .replace(newsCurrentLocaleInPath, `${otherLocale.toLocaleLowerCase()}`); const t = translate(currentLocale); --- { t(tPage, { key: 'language-link-text', language: t(tSite, { key: 'locale', locale: otherLocale }), }) }