Skip to content
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

Merged

Conversation

lucas-koehler
Copy link
Contributor

@lucas-koehler lucas-koehler commented May 24, 2022

  • 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
  • Add Internationalizable interface and isInternationalized type guard to clearly define internationalizable UISchema elements.

Fix #1942

@lucas-koehler lucas-koehler requested a review from sdirix May 24, 2022 15:56
@coveralls
Copy link

coveralls commented May 24, 2022

Coverage Status

Coverage remained the same at 84.29% when pulling 141eb26 on lucas-koehler:polish-translation-feature into a3d2ac0 on eclipsesource:master.

@@ -8,7 +8,10 @@ export const getI18nKeyPrefixBySchema = (
schema: i18nJsonSchema | undefined,
uischema: UISchemaElement | undefined
): string | undefined => {
return uischema?.options?.i18n ?? schema?.i18n ?? undefined;
if (uischema && isControlElement(uischema) && uischema.i18n) {
Copy link
Member

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.

@@ -213,6 +213,11 @@ export interface ControlElement extends UISchemaElement, Scopable {
* An optional label that will be associated with the control
*/
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.
Copy link
Member

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.

@@ -244,6 +249,9 @@ export interface Categorization extends UISchemaElement {
elements: (Category | Categorization)[];
}

export const isControlElement = (element: UISchemaElement): element is ControlElement =>
Copy link
Member

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
@lucas-koehler
Copy link
Contributor Author

@sdirix Thanks for the review. I rebased the changes onto master and added a second commit that provides a new Internationalizable interface and a typeguard checking whether its i18n property is set.

@@ -244,6 +253,10 @@ export interface Categorization extends UISchemaElement {
elements: (Category | Categorization)[];
}

export const isInternationalizable = (element: unknown): element is Required<Internationalizable> => {
Copy link
Member

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.

Suggested change
export const isInternationalizable = (element: unknown): element is Required<Internationalizable> => {
export const isInternationalized = (element: unknown): element is Required<Internationalizable> => {

@lucas-koehler
Copy link
Contributor Author

lucas-koehler commented Jun 2, 2022

@sdirix Thanks for the suggestion. That indeed fits better :) I adapted the commit to name the new type guard isInternationalized.

@lucas-koehler lucas-koehler requested a review from sdirix June 2, 2022 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Polish translation feature
3 participants