-
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 |
|---|---|---|
|
|
@@ -94,9 +94,12 @@ 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', | ||
| optional: 'optional', | ||
| essentialInfo: 'essential_info', | ||
| optionalInfo: 'optional_info', | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -140,14 +143,32 @@ 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
+146
to
+160
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']); | ||
| /** | ||
| * 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'; | ||
|
|
||
| /** | ||
| * Method to check whether master toggle button is checked or not | ||
|
|
@@ -223,6 +244,7 @@ const Consent: FC<ConsentProps> = ({ | |
| purpose={purpose} | ||
| formValues={formValues} | ||
| onInputChange={onInputChange} | ||
| t={t} | ||
| /> | ||
| </div> | ||
| )} | ||
|
|
@@ -252,6 +274,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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Use one fallback contract for consent translation keys.
Both sites allow internal lookup keys to reach rendered text.
packages/react/src/components/adapters/Consent.tsx#L97-L102: keep lookup-key defaults separate from display defaults whentandmetaare absent.packages/react/src/components/adapters/ConsentCheckboxList.tsx#L101-L115: return an empty string whent('consent.<key>')is untranslated instead of returning the raw claim key.The supplied PR objective requires unresolved consent translations to produce an empty string.
📍 Affects 2 files
packages/react/src/components/adapters/Consent.tsx#L97-L102(this comment)packages/react/src/components/adapters/ConsentCheckboxList.tsx#L101-L115🤖 Prompt for AI Agents