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

Chore: create the no-untranslated-literals rule #88271

Merged
merged 23 commits into from
May 29, 2024

Conversation

eledobleefe
Copy link
Contributor

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:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@eledobleefe eledobleefe added area/frontend internal for issues made by grafanistas labels May 24, 2024
@eledobleefe eledobleefe self-assigned this May 24, 2024
@eledobleefe eledobleefe requested review from a team and grafanabot as code owners May 24, 2024 08:59
@eledobleefe eledobleefe requested review from tskarhed, ashharrison90 and oshirohugo and removed request for a team May 24, 2024 08:59
@eledobleefe eledobleefe added no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes labels May 24, 2024
@eledobleefe eledobleefe added this to the 11.1.x milestone May 24, 2024
Copy link
Contributor

@joshhunt joshhunt left a 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.
Copy link
Contributor

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.

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 we could shift this to the bottom. as a consumer of the rule i don't care about the implementation details so much 🤔

Copy link
Contributor

@ashharrison90 ashharrison90 left a 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/README.md 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.
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 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>

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 we could do with a {t()} example here:

// Good ✅
<InlineToast placement="top" referenceElement={buttonRef.current}>
  {t('clipboard-button.inline-toast.success', 'Copied')}
</InlineToast>

Copy link
Contributor Author

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?

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 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? 🤔

Copy link
Contributor

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>

Copy link
Contributor Author

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/README.md Outdated Show resolved Hide resolved
packages/grafana-eslint-rules/README.md Outdated Show resolved Hide resolved
packages/grafana-eslint-rules/README.md Outdated Show resolved Hide resolved
packages/grafana-eslint-rules/README.md Outdated Show resolved Hide resolved
<InlineToast placement="top" referenceElement={buttonRef.current}>
<Trans i18nKey="clipboard-button.inline-toast.success">Copied</Trans>
</InlineToast>

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 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? 🤔

packages/grafana-eslint-rules/README.md Outdated Show resolved Hide resolved
<InlineToast placement="top" referenceElement={buttonRef.current}>
<Trans i18nKey="clipboard-button.inline-toast.success">Copied</Trans>
</InlineToast>

Copy link
Contributor

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>

packages/grafana-eslint-rules/README.md Outdated Show resolved Hide resolved

//Good ✅
const serviceName = service.name;
<Trans i18nKey="login.services.sing-in-with-prefix">Sign in with {{ serviceName }}</Trans>;
Copy link
Contributor

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.
Copy link
Contributor

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? 🤔

Copy link
Contributor

@ashharrison90 ashharrison90 left a comment

Choose a reason for hiding this comment

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

lgtm 👍

@eledobleefe eledobleefe merged commit a47e71f into main May 29, 2024
16 checks passed
@eledobleefe eledobleefe deleted the eledobleefe/i18n-no-literals-eslint-87897 branch May 29, 2024 11:04
bergquist added a commit that referenced this pull request May 29, 2024
* 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)
  ...
miguelmolina95 pushed a commit to miguelmolina95/grafana that referenced this pull request Jun 3, 2024
@kevinwcyu kevinwcyu modified the milestones: 11.1.x, 11.1.0 Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/frontend internal for issues made by grafanistas no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

i18n - rules & metrics: create ESlint rule
5 participants