-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internationalize purpose descriptions (#181)
* internationalize purpose descriptions * no comment * errors * display desc for essential * naming and use airgap purpose title and description over default * no camelcase * hard code essential and fix enum * version bump * consistent default titles * fix inverted * pull custom desc if available * pretty * pretty * pretty * prettier * post review * fix * prettier
- Loading branch information
1 parent
ccef9be
commit 395c9bb
Showing
9 changed files
with
203 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ConsentSelection } from '../types'; | ||
|
||
import { useMemo } from 'preact/hooks'; | ||
|
||
import { DefinedMessage } from '@transcend-io/internationalization'; | ||
|
||
const PURPOSE_MESSAGE_PREFIX = 'purpose.trackingType'; | ||
|
||
export const useGetInvertedPurposeMessageKeys = ({ | ||
consentSelection, | ||
defaultPurposeToMessageKey, | ||
}: { | ||
/** The configured airgap purpose types */ | ||
consentSelection: ConsentSelection; | ||
/** The lookup of messages for default purpose types */ | ||
defaultPurposeToMessageKey: Record<string, DefinedMessage>; | ||
}): Record<string, DefinedMessage> => { | ||
const purposeToMessageKey: Record<string, DefinedMessage> = useMemo( | ||
() => | ||
// the purpose type is unique for the bundle | ||
[...Object.keys(consentSelection ?? {}), 'Essential'].reduce( | ||
(allMessages, purposeType) => { | ||
if (allMessages[purposeType]) { | ||
return allMessages; | ||
} | ||
const purposeMessageLabel = `${PURPOSE_MESSAGE_PREFIX}.${purposeType}.title`; | ||
return { | ||
...allMessages, | ||
[purposeType]: { | ||
id: purposeMessageLabel, | ||
defaultMessage: defaultPurposeToMessageKey[purposeType]?.defaultMessage | ||
|| purposeType, | ||
description: `Translatable name for purpose '${purposeType}'`, | ||
} as DefinedMessage, | ||
}; | ||
}, | ||
defaultPurposeToMessageKey as Record<string, DefinedMessage>, | ||
), | ||
[consentSelection, defaultPurposeToMessageKey], | ||
); | ||
|
||
return purposeToMessageKey; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { | ||
TrackingPurposesTypes, | ||
} from '@transcend-io/airgap.js-types'; | ||
|
||
import { ConsentSelection } from '../types'; | ||
|
||
import { useMemo } from 'preact/hooks'; | ||
|
||
import { DefinedMessage } from '@transcend-io/internationalization'; | ||
|
||
const PURPOSE_MESSAGE_PREFIX = 'purpose.trackingType'; | ||
|
||
export const useGetPurposeDescriptionKeys = ({ | ||
consentSelection, | ||
defaultPurposeToDescriptionKey, | ||
airgapPurposes, | ||
}: { | ||
/** The configured airgap purpose types */ | ||
consentSelection: ConsentSelection; | ||
/** The lookup of messages for default purpose types */ | ||
defaultPurposeToDescriptionKey: Record<string, DefinedMessage>; | ||
/** Airgap purposes data */ | ||
airgapPurposes: TrackingPurposesTypes; | ||
}): Record<string, DefinedMessage> => { | ||
const purposeToDescriptionKey: Record<string, DefinedMessage> = useMemo( | ||
() => | ||
// hard-coding Essential since it's not provided by consentSelection | ||
[...Object.keys(consentSelection ?? {}), 'Essential'].reduce((allMessages, purposeType) => { | ||
// making sure default message for Essential is not overwritten | ||
// by missing Essential message from airgap | ||
if (airgapPurposes[purposeType]?.description) { | ||
const purposeMessageDescriptionId = `${PURPOSE_MESSAGE_PREFIX}.${purposeType}.description`; | ||
return { | ||
...allMessages, | ||
[purposeType]: { | ||
id: purposeMessageDescriptionId, | ||
defaultMessage: airgapPurposes[purposeType]?.description, | ||
description: `Translatable description for purpose '${purposeType}'`, | ||
} as DefinedMessage, | ||
}; | ||
} | ||
return {...allMessages}; | ||
}, defaultPurposeToDescriptionKey as Record<string, DefinedMessage>), | ||
[consentSelection, defaultPurposeToDescriptionKey], | ||
); | ||
|
||
return purposeToDescriptionKey; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters