diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/data/committee.ts | 2 | ||||
| -rw-r--r-- | src/i18n/translate.ts | 14 | ||||
| -rw-r--r-- | src/i18n/translations/enums/committeeRole.ts | 21 | ||||
| -rw-r--r-- | src/pages/[locale]/index.astro | 5 | ||||
| -rw-r--r-- | src/types/CommitteeMember.d.ts | 2 | ||||
| -rw-r--r-- | src/types/TranslationsDictionary.d.ts | 2 |
6 files changed, 35 insertions, 11 deletions
diff --git a/src/data/committee.ts b/src/data/committee.ts index fd6d428..da936b8 100644 --- a/src/data/committee.ts +++ b/src/data/committee.ts @@ -1,5 +1,5 @@ import type { CommitteeMember } from '$types/CommitteeMember'; -import CommitteeRole from 'enums/CommitteeRole'; +import CommitteeRole from '$enums/CommitteeRole'; const committee: CommitteeMember[] = [ { diff --git a/src/i18n/translate.ts b/src/i18n/translate.ts index a9415b2..8f27e4b 100644 --- a/src/i18n/translate.ts +++ b/src/i18n/translate.ts @@ -1,8 +1,12 @@ +import type CommitteeRole from '$enums/CommitteeRole'; import type Locale from '$types/Locale'; import type { TranslationsDictionary, Translation } from '$types/TranslationsDictionary'; import { defaultLocale } from './locales'; -type TranslationsDictionaryWith<Key extends string, Params> = TranslationsDictionary<{ +type TranslationsDictionaryWith< + Key extends string | CommitteeRole, + Params, +> = TranslationsDictionary<{ [key in Key]: { [locale in typeof defaultLocale]: Translation<Params> } & { [locale in Locale]?: Translation<Params>; }; @@ -14,6 +18,14 @@ export default function (locale: Locale) { Params, Dict extends TranslationsDictionaryWith<Key, Params>, >(dict: Dict, params: { key: Key } & { [Param in keyof Params]: string }) { + if (!(params.key in dict)) { + throw new Error(` + Could not find translation for key '${params.key}'. Available keys were: + ${Object.keys(dict) + .map((k) => `'${k}'`) + .join(', ')} + `); + } const translation = dict[params.key][locale] ?? dict[params.key][defaultLocale]; return translation(params); }; diff --git a/src/i18n/translations/enums/committeeRole.ts b/src/i18n/translations/enums/committeeRole.ts index 06b9980..0d13b18 100644 --- a/src/i18n/translations/enums/committeeRole.ts +++ b/src/i18n/translations/enums/committeeRole.ts @@ -1,27 +1,34 @@ import type { TranslationsDictionary } from '$types/TranslationsDictionary'; -import CommitteeRole from 'enums/CommitteeRole'; const tEnum = { - [CommitteeRole.Preses]: { + Preses: { sco: () => 'Preses', 'en-GB': () => 'President', }, - [CommitteeRole.Secretar]: { + Secretar: { sco: () => 'Secretar', - 'en-GB': () => 'Secretar', + 'en-GB': () => 'Secretary', }, - [CommitteeRole.Thesaurer]: { + Thesaurer: { sco: () => 'Thesaurer', 'en-GB': () => 'Treasurer', }, - [CommitteeRole.Wabmaister]: { + MemmershipSecretar: { + sco: () => 'Memmership Secretar', + 'en-GB': () => 'Membership Secretary', + }, + Wabmaister: { sco: () => 'Wabmaister', 'en-GB': () => 'Webmaster', }, - [CommitteeRole.LallansEiditor]: { + LallansEiditor: { sco: () => 'Lallans Eiditor', 'en-GB': () => 'Lallans Editor', }, + HonoraryPreses: { + sco: () => 'Honorary Preses', + 'en-GB': () => 'Honorary President', + }, }; type Raw = typeof tEnum; diff --git a/src/pages/[locale]/index.astro b/src/pages/[locale]/index.astro index cb38bc5..b47a045 100644 --- a/src/pages/[locale]/index.astro +++ b/src/pages/[locale]/index.astro @@ -3,12 +3,14 @@ import Page from '$layouts/Page.astro'; import localeStaticPaths from '$lib/localeStaticPaths'; import translate from '$i18n/translate'; import tPage from '$i18n/translations/pages/home'; +import tRole from '$i18n/translations/enums/committeeRole'; import type Locale from '$types/Locale'; import { getMostRecentNewsItem } from '$lib/newsUtils'; import contactDetails from '$data/contactDetails'; import NewsIndex from '$components/NewsIndex/NewsIndex.astro'; import committee from '$data/committee'; import Button from '$components/Button.astro'; +import CommitteeRole from '$enums/CommitteeRole'; export async function getStaticPaths() { return localeStaticPaths; @@ -51,6 +53,9 @@ const mostRecentNewsItem = await getMostRecentNewsItem(locale); )} <div class="committee__member__text"> <h4>{member.name}</h4> + <p class="italic"> + {member.roles.map((role) => t(tRole, { key: CommitteeRole[role] })).join(', ')} + </p> {member.bio && <p set:html={member.bio[locale]} />} </div> </li> diff --git a/src/types/CommitteeMember.d.ts b/src/types/CommitteeMember.d.ts index e17bb4c..d9f8ee3 100644 --- a/src/types/CommitteeMember.d.ts +++ b/src/types/CommitteeMember.d.ts @@ -1,4 +1,4 @@ -import type CommitteeRole from 'enums/CommitteeRole'; +import type CommitteeRole from '$enums/CommitteeRole'; import type Locale from './Locale'; type CommitteeMember = { diff --git a/src/types/TranslationsDictionary.d.ts b/src/types/TranslationsDictionary.d.ts index d9d7e44..5033ecd 100644 --- a/src/types/TranslationsDictionary.d.ts +++ b/src/types/TranslationsDictionary.d.ts @@ -4,7 +4,7 @@ import type Locale from './Locale'; export type Translation<Params> = (params: { [key in keyof Params]: string }) => string; export type TranslationsDictionary<Raw> = { - [key in keyof Raw]: { + readonly [key in keyof Raw]: { [locale in Locale]?: Translation<Parameters<Raw[key][typeof defaultLocale]>[0]>; } & { [locale in typeof defaultLocale]: Translation<Parameters<Raw[key][typeof defaultLocale]>[0]>; |
