From 5d3c0f6139eb53523966a254e89d8010c19dbb90 Mon Sep 17 00:00:00 2001 From: Joe Carstairs <65492573+Sycamost@users.noreply.github.com> Date: Fri, 18 Aug 2023 18:43:46 +0100 Subject: Better typing on long-date translations --- src/i18n/translations/site.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/i18n/translations/site.ts b/src/i18n/translations/site.ts index f1f0cd3..7d48670 100644 --- a/src/i18n/translations/site.ts +++ b/src/i18n/translations/site.ts @@ -2,7 +2,6 @@ import type Date from '$types/Date'; import type Month from '$types/Month'; import type Locale from '$types/Locale'; import type { TranslationsDictionary } from '$types/TranslationsDictionary'; -import locales from '../locales'; const tSite = { title: { @@ -55,18 +54,10 @@ const tSite = { } }, }, - 'long-date': Object.fromEntries( - locales.map((locale) => { - return [ - locale, - ({ date }: { date: Date }) => ` - ${tSite['ordinal'][locale]({ n: date.slice(8) })} - ${tSite['month'][locale]({ month: date.slice(5, 7) as Month })} - ${date.slice(0, 4)} - `, - ]; - }) - ), + 'long-date': { + sco: longDate('sco'), + 'en-GB': longDate('en-GB'), + }, ordinal: { sco: ({ n }: { n: string }) => { const m = n.replace(/^0+/, ''); @@ -179,5 +170,13 @@ const tSite = { }, }; +function longDate(locale: Locale) { + return ({ date }: { date: Date }) => ` + ${tSite['ordinal'][locale]({ n: date.slice(8) })} + ${tSite['month'][locale]({ month: date.slice(5, 7) as Month })} + ${date.slice(0, 4)} + `; +} + type Raw = typeof tSite; export default tSite as TranslationsDictionary; -- cgit v1.2.3