diff options
| author | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2023-08-23 20:05:41 +0100 |
|---|---|---|
| committer | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2023-08-23 20:31:20 +0100 |
| commit | 52fa5e27fc37bc156ef722c8258646057a8a826d (patch) | |
| tree | dea6e5e3c78c808360d3fa36d96c89d31f75fc8b /src/i18n/translate.ts | |
| parent | 8a4964fbd8fe8064ee643f135e17fab640a48ce7 (diff) | |
Displays committee role
Diffstat (limited to 'src/i18n/translate.ts')
| -rw-r--r-- | src/i18n/translate.ts | 14 |
1 files changed, 13 insertions, 1 deletions
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); }; |
