-
Notifications
You must be signed in to change notification settings - Fork 21
#4977 Multilingual support for claims title and its value #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,8 +41,10 @@ export interface ConsentRenderProps { | |
| export interface ConsentConfig { | ||
| essential?: string; | ||
| optional?: string; | ||
| permission?: string; | ||
| essentialInfo?: string; | ||
| optionalInfo?: string; | ||
| permissionInfo?: string; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -94,9 +96,14 @@ export interface ConsentProps { | |
| t?: UseTranslation['t']; | ||
| } | ||
|
|
||
| const defaultConfig: Required<Pick<ConsentConfig, 'essential' | 'optional'>> = { | ||
| essential: 'Essential Attributtes', | ||
| optional: 'Optional Attributes', | ||
| // default config for consent related translation keys | ||
| const defaultConfig: ConsentConfig = { | ||
| essential: 'essential_claims', | ||
| optional: 'optional_claims', | ||
| permission: 'authorize_scope', | ||
| essentialInfo: 'essential_claims_info', | ||
| optionalInfo: 'optional_claims_info', | ||
| permissionInfo: 'authorize_scope_info', | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -140,14 +147,34 @@ const Consent: FC<ConsentProps> = ({ | |
| if (!text || (!t && !meta)) { | ||
| return text || ''; | ||
| } | ||
| return resolveFlowTemplateLiterals(text, {meta, t: t || ((k: string): string => k)}); | ||
| // first check if the key is present in the translation file, | ||
| // if not then resolve the template literals | ||
| const consentKey = `consent.${text}`; | ||
| const translated: string = t ? t(consentKey) : consentKey; | ||
|
|
||
| // if the translated value is same as the consent key, | ||
| // then resolve the template literals | ||
| const resolvedValue = | ||
| translated === consentKey | ||
| ? resolveFlowTemplateLiterals(text, {meta, t: t || ((k: string): string => k)}) | ||
| : translated; | ||
|
|
||
| // if the resolved value is same as the original text, | ||
| // then return empty string | ||
| return resolvedValue === text ? '' : resolvedValue; | ||
|
Comment on lines
+150
to
+164
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift Reject partially unresolved template results.
Track unresolved expressions explicitly, or make the shared resolver report an unresolved result before returning the value. This follows the supplied 🤖 Prompt for AI Agents |
||
| }; | ||
|
|
||
| const config: ConsentConfig = {...defaultConfig, ...suppliedConfig}; | ||
| const essentialInfo = typeof config.essentialInfo === 'string' ? resolve(config.essentialInfo.trim()) : ''; | ||
| const optionalInfo = typeof config.optionalInfo === 'string' ? resolve(config.optionalInfo.trim()) : ''; | ||
| const essentialLabel = resolve(config['essential']); | ||
| const optionalLabel = resolve(config['optional']); | ||
| const essentialInfo = resolve(config['essentialInfo']); | ||
| const optionalInfo = resolve(config['optionalInfo']); | ||
| const permissionInfo = resolve(config['permissionInfo']); | ||
| /** | ||
| * Falls back to default config values if essential/optional keys | ||
| * cannot be resolved via translation files or meta template literals. | ||
| */ | ||
| const essentialLabel = resolve(config['essential']) || 'Essential Attributes'; | ||
| const optionalLabel = resolve(config['optional']) || 'Optional Attributes'; | ||
| const permissionLabel = resolve(config['permission']) || 'Permissions'; | ||
|
|
||
| /** | ||
| * Method to check whether master toggle button is checked or not | ||
|
|
@@ -223,6 +250,7 @@ const Consent: FC<ConsentProps> = ({ | |
| purpose={purpose} | ||
| formValues={formValues} | ||
| onInputChange={onInputChange} | ||
| t={t} | ||
| /> | ||
| </div> | ||
| )} | ||
|
|
@@ -232,10 +260,11 @@ const Consent: FC<ConsentProps> = ({ | |
| <div className={optionalSectionHeaderClass}> | ||
| <div className={optionalSectionLabelClass}> | ||
| <Typography variant="subtitle2" fontWeight="bold"> | ||
| {purpose.type === 'permissions' ? 'Permissions' : optionalLabel} | ||
| {purpose.type === 'permissions' ? permissionLabel : optionalLabel} | ||
| </Typography> | ||
| {optionalInfo !== '' && ( | ||
| <Tooltip helperText={optionalInfo}> | ||
| {/* Show tooltip for optional claims/permissions according to their type */} | ||
| {Boolean(purpose.type === 'permissions' ? permissionInfo : optionalInfo) && ( | ||
| <Tooltip helperText={purpose.type === 'permissions' ? permissionInfo : optionalInfo}> | ||
| <Info width="1rem" height="1rem" /> | ||
| </Tooltip> | ||
| )} | ||
|
|
@@ -252,6 +281,7 @@ const Consent: FC<ConsentProps> = ({ | |
| purpose={purpose} | ||
| formValues={formValues} | ||
| onInputChange={onInputChange} | ||
| t={t} | ||
| /> | ||
| </div> | ||
| )} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zesu22 instead of this config approach, shall we hard code the i18n keys in the consent UI component with the inline english fallbacks (existing)?
I don't like this config approach which introduces another concept to the flow definition to define fixed key value pairs for i18n. Ideal solution would be to define consent input layout in the flow definition (prompt node) with the i18n keys and let it get rendered dynamically at runtime. Then sdk will resolve i18n keys with the flow/meta response.
But due to the limitations with the current implementation, consent input has a fixed layout that cannot be customized from the flow definition. This needs to be improved in future.
For the moment, we can use a set of hard coded i18n keys for the consent input.