From 7781c69153e3956ca14684fe9a287fbbb8a01082 Mon Sep 17 00:00:00 2001 From: Joe Carstairs <65492573+Sycamost@users.noreply.github.com> Date: Sun, 13 Aug 2023 20:41:29 +0100 Subject: Determines current locale with lib function --- src/components/LallansIssue.astro | 8 ++++---- src/components/LallansIssueContributions.astro | 6 +++--- src/components/LallansIssuesGallery.astro | 9 ++------- src/components/Navbar.astro | 11 +++-------- src/components/Scotsoun.astro | 6 +++--- src/components/ScotsounCdGallery.astro | 9 ++------- src/components/SwitchLanguageLink.astro | 7 ++----- src/layouts/Layout.astro | 8 ++++---- src/layouts/Page.astro | 6 ++---- src/lib/getLocaleFromPath.ts | 11 +++++++++++ src/pages/[locale]/furthsettins/index.astro | 2 +- .../[locale]/furthsettins/lallans/[issueNumber]/index.astro | 4 ++-- .../lallans/[issueNumber]/payment-success-confirmation.astro | 2 +- src/pages/[locale]/furthsettins/lallans/index.astro | 4 ++-- .../[locale]/furthsettins/scotsoun/[scotsounId]/index.astro | 4 ++-- .../scotsoun/[scotsounId]/payment-success-confirmation.astro | 2 +- src/pages/[locale]/furthsettins/scotsoun/index.astro | 4 ++-- src/pages/[locale]/index.astro | 2 +- 18 files changed, 48 insertions(+), 57 deletions(-) create mode 100644 src/lib/getLocaleFromPath.ts (limited to 'src') diff --git a/src/components/LallansIssue.astro b/src/components/LallansIssue.astro index a07d345..690e96c 100644 --- a/src/components/LallansIssue.astro +++ b/src/components/LallansIssue.astro @@ -1,19 +1,19 @@ --- import translate from '$i18n/translate'; import tSite from '$i18n/translations/site'; +import getLocaleFromPath from '$lib/getLocaleFromPath'; import relativePath from '$lib/relativePath'; import type LallansIssue from '$types/LallansIssue'; -import type Locale from '$types/Locale'; import LallansIssueContributions from './LallansIssueContributions.astro'; import LallansIssueContributors from './LallansIssueContributors.astro'; import PayPalButtons from './PayPalButtons.astro'; interface Props { issue: LallansIssue; - locale: Locale; } -const { issue, locale } = Astro.props; +const { issue } = Astro.props; +const locale = getLocaleFromPath(Astro.url.pathname); const t = translate(locale); --- @@ -36,7 +36,7 @@ const t = translate(locale);
{ 'contributions' in issue ? ( - + ) : ( 'contributors' in issue && ) diff --git a/src/components/LallansIssueContributions.astro b/src/components/LallansIssueContributions.astro index 425f66a..9cf46da 100644 --- a/src/components/LallansIssueContributions.astro +++ b/src/components/LallansIssueContributions.astro @@ -1,15 +1,15 @@ --- import translate from '$i18n/translate'; import tSite from '$i18n/translations/site'; +import getLocaleFromPath from '$lib/getLocaleFromPath'; import type { Contribution } from '$types/LallansIssue'; -import type Locale from '$types/Locale'; interface Props { contributions: Contribution[]; - locale: Locale; } -const { contributions, locale } = Astro.props; +const { contributions } = Astro.props; +const locale = getLocaleFromPath(Astro.url.pathname); const t = translate(locale); --- diff --git a/src/components/LallansIssuesGallery.astro b/src/components/LallansIssuesGallery.astro index c784156..f3db9b3 100644 --- a/src/components/LallansIssuesGallery.astro +++ b/src/components/LallansIssuesGallery.astro @@ -1,13 +1,8 @@ --- import { getAllLallansIssues } from '$data/lallans'; -import type Locale from '$types/Locale'; - -interface Props { - locale: Locale; -} - -const { locale } = Astro.props; +import getLocaleFromPath from '$lib/getLocaleFromPath'; +const locale = getLocaleFromPath(Astro.url.pathname); const issues = await getAllLallansIssues(); --- diff --git a/src/components/Navbar.astro b/src/components/Navbar.astro index 45cf96b..c4e31b2 100644 --- a/src/components/Navbar.astro +++ b/src/components/Navbar.astro @@ -1,16 +1,11 @@ --- -import type Locale from '$types/Locale'; import Breadcrumbs from './Breadcrumbs.astro'; import SwitchLanguageLink from './SwitchLanguageLink.astro'; import tSite from '$i18n/translations/site'; import translate from '$i18n/translate'; +import getLocaleFromPath from '$lib/getLocaleFromPath'; -interface Props { - locale: Locale; -} - -const { locale } = Astro.props; - +const locale = getLocaleFromPath(Astro.url.pathname); const t = translate(locale); --- @@ -20,6 +15,6 @@ const t = translate(locale); {t(tSite, { key: 'scots-leid-associe' })}

- + diff --git a/src/components/Scotsoun.astro b/src/components/Scotsoun.astro index 1491ebc..a0600d1 100644 --- a/src/components/Scotsoun.astro +++ b/src/components/Scotsoun.astro @@ -2,17 +2,17 @@ import translate from '$i18n/translate'; import tSite from '$i18n/translations/site'; import tComponent from '$i18n/translations/components/scotsoun'; -import type Locale from '$types/Locale'; import type Scotsoun from '$types/Scotsoun'; import PayPalButtons from './PayPalButtons.astro'; import relativePath from '$lib/relativePath'; +import getLocaleFromPath from '$lib/getLocaleFromPath'; interface Props { - locale: Locale; scotsoun: Scotsoun; } -const { locale, scotsoun } = Astro.props; +const { scotsoun } = Astro.props; +const locale = getLocaleFromPath(Astro.url.pathname); const t = translate(locale); --- diff --git a/src/components/ScotsounCdGallery.astro b/src/components/ScotsounCdGallery.astro index 6f6c794..0a8cd92 100644 --- a/src/components/ScotsounCdGallery.astro +++ b/src/components/ScotsounCdGallery.astro @@ -1,13 +1,8 @@ --- import { getAllScotsoun } from '$data/scotsoun'; -import type Locale from '$types/Locale'; - -interface Props { - locale: Locale; -} - -const { locale } = Astro.props; +import getLocaleFromPath from '$lib/getLocaleFromPath'; +const locale = getLocaleFromPath(Astro.url.pathname); const scotsoun = await getAllScotsoun(); --- diff --git a/src/components/SwitchLanguageLink.astro b/src/components/SwitchLanguageLink.astro index 96dd538..62de1ba 100644 --- a/src/components/SwitchLanguageLink.astro +++ b/src/components/SwitchLanguageLink.astro @@ -3,13 +3,10 @@ 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; -} +import getLocaleFromPath from '$lib/getLocaleFromPath'; // This logic assumes that there are exactly two locales. -const { currentLocale } = Astro.props; +const currentLocale = getLocaleFromPath(Astro.url.pathname); const otherLocale: Locale = currentLocale === 'sco' ? 'en-GB' : 'sco'; const currentPath = Astro.url.pathname; const currentLocaleInPath = new RegExp(`(?<=^/)(${currentLocale}/)?`); diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 9bca7e1..54b8c25 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -3,14 +3,14 @@ import Footer from '$components/Footer.astro'; import Navbar from '$components/Navbar.astro'; import translate from '$i18n/translate'; import site from '$i18n/translations/site'; -import type Locale from '$types/Locale'; +import getLocaleFromPath from '$lib/getLocaleFromPath'; interface Props { - locale: Locale; title: string; } -const { locale, title } = Astro.props; +const { title } = Astro.props; +const locale = getLocaleFromPath(Astro.url.pathname); const t = translate(locale); --- @@ -27,7 +27,7 @@ const t = translate(locale); {title} | {t(site, { key: 'title' })} - +