From a9f63d838b37e5819e8b52cde5f8d0472aee63aa Mon Sep 17 00:00:00 2001 From: Joe Carstairs <65492573+Sycamost@users.noreply.github.com> Date: Mon, 14 Aug 2023 21:12:55 +0100 Subject: SwitchLanguageLink works for news items --- src/components/SwitchLanguageLink.astro | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/components') diff --git a/src/components/SwitchLanguageLink.astro b/src/components/SwitchLanguageLink.astro index 62de1ba..c8733bc 100644 --- a/src/components/SwitchLanguageLink.astro +++ b/src/components/SwitchLanguageLink.astro @@ -10,7 +10,10 @@ 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 otherLocalePath = currentPath.replace(currentLocaleInPath, `${otherLocale}/`); +const newsCurrentLocaleInPath = new RegExp(`(?<=/news/)(${currentLocale.toLocaleLowerCase()})`); +const otherLocalePath = currentPath + .replace(currentLocaleInPath, `${otherLocale}/`) + .replace(newsCurrentLocaleInPath, `${otherLocale.toLocaleLowerCase()}`); const t = translate(currentLocale); --- -- cgit v1.2.3