From 52fa5e27fc37bc156ef722c8258646057a8a826d Mon Sep 17 00:00:00 2001 From: Joe Carstairs <65492573+Sycamost@users.noreply.github.com> Date: Wed, 23 Aug 2023 20:05:41 +0100 Subject: Displays committee role --- src/i18n/translate.ts | 14 +++++++++++++- src/i18n/translations/enums/committeeRole.ts | 21 ++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) (limited to 'src/i18n') 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 = TranslationsDictionary<{ +type TranslationsDictionaryWith< + Key extends string | CommitteeRole, + Params, +> = TranslationsDictionary<{ [key in Key]: { [locale in typeof defaultLocale]: Translation } & { [locale in Locale]?: Translation; }; @@ -14,6 +18,14 @@ export default function (locale: Locale) { Params, Dict extends TranslationsDictionaryWith, >(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; -- cgit v1.2.3