summaryrefslogtreecommitdiff
path: root/src/i18n/translate.ts
diff options
context:
space:
mode:
authorJoe Carstairs <65492573+joeacarstairs@users.noreply.github.com>2024-01-25 17:02:50 +0000
committerGitHub <noreply@github.com>2024-01-25 17:02:50 +0000
commit64c5ee53a0d158b38caff3285dac008826d7ae88 (patch)
tree7542f8c5b82b3327d82cc5defe2e84f86d6f11e7 /src/i18n/translate.ts
parent7140956da0820d4b818119eff7dfc72345f3328e (diff)
Update from staging (#70)
* 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 * Replaces a few straggler --margins with --spacing (#67) --------- Co-authored-by: Joe Carstairs <118172583+jcarstairs-scottlogic@users.noreply.github.com>
Diffstat (limited to 'src/i18n/translate.ts')
-rw-r--r--src/i18n/translate.ts28
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);
};
}