blob: 96dd5384fefd50a68e8a9543745773273f33700c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
---
import tPage from '$i18n/translations/components/languageLinks';
import tSite from '$i18n/translations/site';
import translate from '$i18n/translate';
import type Locale from '$types/Locale';
interface Props {
currentLocale: Locale;
}
// This logic assumes that there are exactly two locales.
const { currentLocale } = Astro.props;
const otherLocale: Locale = currentLocale === 'sco' ? 'en-GB' : 'sco';
const currentPath = Astro.url.pathname;
const currentLocaleInPath = new RegExp(`(?<=^/)(${currentLocale}/)?`);
const otherLocalePath = currentPath.replace(currentLocaleInPath, `${otherLocale}/`);
const t = translate(currentLocale);
---
<a class="link switch-language-link" href={otherLocalePath}>
{
t(tPage, {
key: 'language-link-text',
language: t(tSite, { key: 'locale', locale: otherLocale }),
})
}
</a>
|