-
Notifications
You must be signed in to change notification settings - Fork 416
Move i18n key specification from UI Schema options to ControlElement #1944
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
Move i18n key specification from UI Schema options to ControlElement #1944
Conversation
packages/core/src/i18n/i18nUtil.ts
Outdated
| uischema: UISchemaElement | undefined | ||
| ): string | undefined => { | ||
| return uischema?.options?.i18n ?? schema?.i18n ?? undefined; | ||
| if (uischema && isControlElement(uischema) && uischema.i18n) { |
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.
At the moment we only support it for ControlElements but for this implementation here I would generalize this a bit. For example via an interface Internationalizable which is extended by ControlElement.
The function would then work unchanged for all UI Schema elements of the future instead of only for Controls.
packages/core/src/models/uischema.ts
Outdated
| label?: string | boolean | LabelDescription; | ||
| /** | ||
| * The i18n key for the control. It is used to identify the string that needs to be translated. | ||
| * It is suffixed with `.label`, `.description` and `.error.<keyword>` to derive the corresponding message keys for the control. |
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.
There can be many more suffixes depending on each control. I would only give them as examples.
packages/core/src/models/uischema.ts
Outdated
| elements: (Category | Categorization)[]; | ||
| } | ||
|
|
||
| export const isControlElement = (element: UISchemaElement): element is ControlElement => |
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.
We already have a isControl type guard.
* The i18n base key can no longer be specified as part of the UI Schema `options` * Add optional `i18n` property to `ControlElement` * Adapt i18n key resolution * Add explicit tests for i18n key extraction from UI Schema and Json Schema Fix eclipsesource#1942
43bc382 to
c275f20
Compare
|
@sdirix Thanks for the review. I rebased the changes onto master and added a second commit that provides a new |
packages/core/src/models/uischema.ts
Outdated
| elements: (Category | Categorization)[]; | ||
| } | ||
|
|
||
| export const isInternationalizable = (element: unknown): element is Required<Internationalizable> => { |
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.
I would change the name a bit to better fit the interface name, i.e. ..able -> optional prop and ...ed -> required prop.
| export const isInternationalizable = (element: unknown): element is Required<Internationalizable> => { | |
| export const isInternationalized = (element: unknown): element is Required<Internationalizable> => { |
c275f20 to
141eb26
Compare
|
@sdirix Thanks for the suggestion. That indeed fits better :) I adapted the commit to name the new type guard |
optionsi18nproperty toControlElementInternationalizableinterface andisInternationalizedtype guard to clearly define internationalizable UISchema elements.Fix #1942