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

translate array controls in material renderers #2099

Merged

Conversation

LukasBoll
Copy link
Contributor

translate array controls in material renderers

@netlify
Copy link

netlify bot commented Feb 20, 2023

Deploy Preview for jsonforms-examples ready!

Name Link
🔨 Latest commit 1150122
🔍 Latest deploy log https://app.netlify.com/sites/jsonforms-examples/deploys/6405e50ed31591000794bf72
😎 Deploy Preview https://deploy-preview-2099--jsonforms-examples.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@coveralls
Copy link

coveralls commented Feb 21, 2023

Coverage Status

Coverage: 83.193%. Remained the same when pulling 1150122 on LukasBoll:translateControlElements into 5e8c860 on eclipsesource:master.

Copy link
Contributor

@lucas-koehler lucas-koehler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @LukasBoll , thanks for your pull request :)
I like the general approach of making the array translations available in a typed way.
Please have a look at the inline comments. They are mainly about namings to make things more clear.

Also, testing that translations are properly applied is pretty inconvenient right now. I suggest adding an additional example similar to packages/examples/src/examples/arrays.ts.
The new example could be named Array (i18n)
You can leave out the non-array property and probably do not need the actions to toggle sorting. Instead, the sorting buttons should be shown in the new example to allow checking their aria labels.

@@ -0,0 +1,40 @@
export interface DefaultTranslation {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename this interface to ArrayDefaultTranslation. The current name suggests that this describes a default translation for any kind of message.

{key: ArrayTranslationEnum.deleteDialogDecline, default: () => 'NO'}
]

export const arrayTranslations: DefaultTranslation[] = Object.values(arrayDefaultTranslations).map(value=>value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The identity map at the end .map(value=>value) seems superfluous to me. Is this really needed?

packages/core/src/i18n/i18nUtil.ts Outdated Show resolved Hide resolved
packages/core/src/i18n/i18nUtil.ts Outdated Show resolved Hide resolved
@@ -123,3 +131,19 @@ export const deriveLabelForUISchemaElement = (uischema: Labelable<boolean>, t: T
const i18nKey = typeof i18nKeyPrefix === 'string' ? `${i18nKeyPrefix}.label` : stringifiedLabel;
return t(i18nKey, stringifiedLabel, { uischema: uischema });
}

export const translateElements = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be renamed to more accurately describe what it does: retrieving translated Array messages.
E.g. the function could be named getArrayTranslations

packages/material-renderers/src/complex/TableToolbar.tsx Outdated Show resolved Hide resolved
packages/material-renderers/src/layouts/ArrayToolbar.tsx Outdated Show resolved Hide resolved
packages/core/src/i18n/arrayTranslations.ts Outdated Show resolved Hide resolved
@@ -37,13 +37,17 @@ export interface DeleteDialogProps {
onClose(): void;
onConfirm(): void;
onCancel(): void;
headerText: string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think title describes more precisely what this is used for. Please rename to title

@LukasBoll LukasBoll force-pushed the translateControlElements branch 2 times, most recently from 0d11318 to b1c5266 Compare February 28, 2023 06:38
Copy link
Contributor

@lucas-koehler lucas-koehler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates :) I just have three small comments.

}
}
},
foo:{type:'string'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed for this example => please delete

Comment on lines 59 to 62
{
type: 'Control',
scope: '#/properties/foo'
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed for this example => please delete


registerExamples([
{
name: 'array (i18n)',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is used as part of the url fragment. Thus, it's better to avoid spaces and parantheses.

Suggested change
name: 'array (i18n)',
name: 'array-i18n',

@LukasBoll
Copy link
Contributor Author

Hi @lucas-koehler,
thank you for the comments and the feedback! I adjusted everything accordingly!

Copy link
Contributor

@lucas-koehler lucas-koehler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now, thanks! I just marked one console.log line to remove that I overlooked earlier.

}
};
export const translate: Translator = (key: string, defaultMessage: string) => {
console.log(key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I forgot this earlier. Please remove this console log before merging :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I just removed the console log

eclipsesource#1826

Co-authored-by: Lucas Koehler <lkoehler@eclipsesource.com>
Copy link
Contributor

@lucas-koehler lucas-koehler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now, thanks for all the updates :)

@lucas-koehler lucas-koehler merged commit b4166e5 into eclipsesource:master Mar 6, 2023
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.

3 participants