From 8a5b11d8322b806ce277c399e51b7f40efcb2556 Mon Sep 17 00:00:00 2001 From: Joe Carstairs <65492573+Sycamost@users.noreply.github.com> Date: Sat, 12 Aug 2023 20:47:32 +0100 Subject: Text color and background colour is controlled by CSS vars --- src/components/SwitchLanguageLink.astro | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/components/SwitchLanguageLink.astro (limited to 'src/components/SwitchLanguageLink.astro') diff --git a/src/components/SwitchLanguageLink.astro b/src/components/SwitchLanguageLink.astro new file mode 100644 index 0000000..77dfa18 --- /dev/null +++ b/src/components/SwitchLanguageLink.astro @@ -0,0 +1,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); +--- + + + { + t(tPage, { + key: 'language-link-text', + language: t(tSite, { key: 'locale', locale: otherLocale }), + }) + } + -- cgit v1.2.3