diff options
| author | Joe Carstairs <118172583+jcarstairs-scottlogic@users.noreply.github.com> | 2024-01-25 16:59:42 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-25 16:59:42 +0000 |
| commit | 1a6eb7e2ff0bf551e1560c67170e90fa8ec2a8ea (patch) | |
| tree | 53f73dcca5693e656d50fac965955560a513a233 /src/i18n/translate.ts | |
| parent | 83c3460191a2089b56b091a7f4e09f39ac636e1e (diff) | |
33 / Pay annual subscription by PayPal (#68)
* Refactors paypal-buttons -> paypal-product-buttons WebComponent
* Pulls out address to data file
* Defines annual subscription prices data hash
* Styles paypal-product-buttons
* Styles <address>
* Details have cursor:pointer on the summary
* Moves Jyne section to separate page
* Rewrites payment options using details components
* Reworks translation typing
* Defines MembershipType enum
* Adds translations for MembershipType enum
* Can pay annual subs by PayPal
* Styles tables better
Diffstat (limited to 'src/i18n/translate.ts')
| -rw-r--r-- | src/i18n/translate.ts | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/i18n/translate.ts b/src/i18n/translate.ts index 8f27e4b..0366798 100644 --- a/src/i18n/translate.ts +++ b/src/i18n/translate.ts @@ -1,23 +1,23 @@ -import type CommitteeRole from '$enums/CommitteeRole'; import type Locale from '$types/Locale'; -import type { TranslationsDictionary, Translation } from '$types/TranslationsDictionary'; +import type { + TranslationsDictionary, + Translation, + LocalesTranslationHash, +} from '$types/TranslationsDictionary'; import { defaultLocale } from './locales'; type TranslationsDictionaryWith< - Key extends string | CommitteeRole, - Params, + Key extends string | number, + ParamsHash extends object, > = TranslationsDictionary<{ - [key in Key]: { [locale in typeof defaultLocale]: Translation<Params> } & { - [locale in Locale]?: Translation<Params>; - }; + [key in Key]: LocalesTranslationHash<ParamsHash>; }>; export default function (locale: Locale) { - return function < - Key extends string, - Params, - Dict extends TranslationsDictionaryWith<Key, Params>, - >(dict: Dict, params: { key: Key } & { [Param in keyof Params]: string }) { + return function <Key extends string | number, ParamsHash extends object>( + dict: TranslationsDictionaryWith<Key, ParamsHash>, + params: { key: Key } & ParamsHash + ) { if (!(params.key in dict)) { throw new Error(` Could not find translation for key '${params.key}'. Available keys were: @@ -26,7 +26,9 @@ export default function (locale: Locale) { .join(', ')} `); } - const translation = dict[params.key][locale] ?? dict[params.key][defaultLocale]; + const localesTranslationHash: LocalesTranslationHash<ParamsHash> = dict[params.key]; + const translation: Translation<ParamsHash> = + localesTranslationHash[locale] ?? localesTranslationHash[defaultLocale]; return translation(params); }; } |
