-
Notifications
You must be signed in to change notification settings - Fork 11.7k
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
Chore: create the no-untranslated-literals
rule
#88271
Conversation
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.
Great job! No comments on the lint rule itself, but I think the docs could do with a little work.
|
||
Check if strings are marked for translation. | ||
|
||
Right now, we only check if a string is wrapped up by the `Trans` tag. We currently do not apply this rule to props, attributes or similars. |
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.
Check out the good docs from @ashharrison90 for the no-unreduced-motion
rule - as these docs are linked to from the lint error message, they should be written with the goal of helping the developer fix their code.
I think they should (very briefly) explain how to use <Trans />
or t()
to translate a phrase, and then link to the rest of the i18n docs like you have.
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 think we could shift this to the bottom. as a consumer of the rule i don't care about the implementation details so much 🤔
packages/grafana-eslint-rules/rules/no-untranslated-literals.cjs
Outdated
Show resolved
Hide resolved
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.
looks great 🙌
packages/grafana-eslint-rules/rules/no-untranslated-literals.cjs
Outdated
Show resolved
Hide resolved
|
||
Check if strings are marked for translation. | ||
|
||
Right now, we only check if a string is wrapped up by the `Trans` tag. We currently do not apply this rule to props, attributes or similars. |
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 think we could shift this to the bottom. as a consumer of the rule i don't care about the implementation details so much 🤔
<InlineToast placement="top" referenceElement={buttonRef.current}> | ||
<Trans i18nKey="clipboard-button.inline-toast.success">Copied</Trans> | ||
</InlineToast> | ||
|
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 think we could do with a {t()}
example here:
// Good ✅
<InlineToast placement="top" referenceElement={buttonRef.current}>
{t('clipboard-button.inline-toast.success', 'Copied')}
</InlineToast>
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.
🤔 But we are not checking this. Would this not trigger misunderstandings?
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 think this is a valid way to translate, and should be shown as an example. there might be occasions where using the t()
variant makes more sense. what misunderstandings can this cause? 🤔
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 still think we should have this as a t()
example as well:
// Good ✅
<InlineToast placement="top" referenceElement={buttonRef.current}>
{t('clipboard-button.inline-toast.success', 'Copied')}
</InlineToast>
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.
🤔 But the internationalization doc says:
Prefer using <Trans /> for JSX children, and t() for props and other javascript usage.
If we are this example, are we not giving the wrong example?
packages/grafana-eslint-rules/rules/no-untranslated-literals.cjs
Outdated
Show resolved
Hide resolved
<InlineToast placement="top" referenceElement={buttonRef.current}> | ||
<Trans i18nKey="clipboard-button.inline-toast.success">Copied</Trans> | ||
</InlineToast> | ||
|
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 think this is a valid way to translate, and should be shown as an example. there might be occasions where using the t()
variant makes more sense. what misunderstandings can this cause? 🤔
<InlineToast placement="top" referenceElement={buttonRef.current}> | ||
<Trans i18nKey="clipboard-button.inline-toast.success">Copied</Trans> | ||
</InlineToast> | ||
|
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 still think we should have this as a t()
example as well:
// Good ✅
<InlineToast placement="top" referenceElement={buttonRef.current}>
{t('clipboard-button.inline-toast.success', 'Copied')}
</InlineToast>
|
||
//Good ✅ | ||
const serviceName = service.name; | ||
<Trans i18nKey="login.services.sing-in-with-prefix">Sign in with {{ serviceName }}</Trans>; |
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.
also think we should have a t()
example here as well
return <input type="value" placeholder={placeholder} />; | ||
``` | ||
|
||
Right now, we only check if a string is wrapped up by the `Trans` tag. We currently do not apply this rule to props, attributes or similar, but we also ask for them to be translated with the `t()` function. |
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.
think this makes more sense as the first sentence in the section? 🤔
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.
lgtm 👍
* main: (25 commits) Update dependency @react-types/overlays to v3.8.7 LogsTable: Fix default sort by time (#88398) Update dependency @react-types/menu to v3.9.9 datatrails: in Components, `model.useState()`, instead of `model.state` (#88432) Update dependency @react-types/button to v3.9.4 Alerting docs: adds template selector docs (#88412) Update dependency @playwright/test to v1.44.1 Update dependency @kusto/monaco-kusto to v10.0.22 Update dependency @grafana/faro-web-sdk to v1.7.3 Alerting: Support `alertingDisableSendAlertsExternal` feature toggle (#88384) Update dependency @grafana/faro-web-sdk to v1.7.3 Add navigation config for `grafana-csp-app` (#88360) Chore: create the `no-untranslated-literals` rule (#88271) Alerting: Update ListAlertRulesQuery to take a slice of RuleGroups (#88385) Update dependency @grafana/faro-core to v1.7.3 Revamp tests for Add/Update Datasource (#88386) Update dependency @floating-ui/react to v0.26.16 (#88409) Update dependency cypress to v13.10.0 (#84140) Add Kubernetes icon (#86677) Update `make docs` procedure (#88404) ...
What is this feature?
We create an ESlint rule to avoid the increase of string literals without being marked for translation. The next step is to decide whether to add this to
eslint
,betterer
, or another option.Why do we need this feature?
To increase the areas in which Grafana has translations available.
Who is this feature for?
Everyone using translations.
Which issue(s) does this PR fix?:
Fixes #87897
Special notes for your reviewer:
Please check that: