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

Topic 6/ Frontend Add alerts related translations #28

Merged
merged 7 commits into from
Jan 14, 2025

Conversation

imenattatra
Copy link

@imenattatra imenattatra commented Dec 13, 2024

Related to the translation project : https://github.com/metr-systems/backlog/issues/3476

What type of PR is this?

This is related to redash translation project and covers texts related to Alerts.

How is this tested?

  • Unit tests (pytest, jest)
  • Manually

This is currently deployed to staging

Follow-up:

  • Translation related to vis-lib

@imenattatra imenattatra changed the title Add alerts translation Topic 6/ Frontend Add alerts related translations Dec 13, 2024
@imenattatra imenattatra changed the base branch from metr-main to epic/ui-translation December 13, 2024 12:42
@imenattatra imenattatra force-pushed the add-alerts-translation branch from c542853 to 24b0480 Compare December 13, 2024 16:50
@imenattatra imenattatra marked this pull request as ready for review January 7, 2025 12:45
@imenattatra imenattatra requested review from helenalebreton and a team January 7, 2025 12:45
@imenattatra imenattatra self-assigned this Jan 7, 2025
@helenalebreton
Copy link

helenalebreton commented Jan 7, 2025

@imenattatra my comments
image
the time parameter is not yet translated

small think here as well when trying to add a destination and no choice is available
image

do you know if there is anything we can do about these ?
image

if not - please do not consider as a priority. At this time it is only a question, and does not need to be addressed in terms of implementation.

Copy link
Collaborator

@berinhard berinhard left a comment

Choose a reason for hiding this comment

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

Thanks a lot @imenattatra for pushing this through. This i18next was a good choice from the API I'm seeing here. I added some comments to better understand it, but I feel we should stick with one strategy on how to do translation and stick with it.

Question: would it be possible to define this t = useTranslation("Alerts") in a single place that can be used by every component? Like a type of global variable?

@@ -113,12 +117,12 @@ class Alert extends React.Component {

return AlertService.save(alert)
.then(alert => {
notification.success("Saved.");
notification.success(i18next.t("Saved."));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we have the Alerts: prefix here too?

Suggested change
notification.success(i18next.t("Saved."));
notification.success(i18next.t("Alerts:Saved."));

Copy link
Author

Choose a reason for hiding this comment

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

because "Saved." is used in many places across the app, i did put it under the common namespace which is set as default, so we don't need to write common:

@@ -56,32 +58,32 @@ export default class AlertEdit extends React.Component {
<DynamicComponent name="AlertEdit.HeaderExtra" alert={alert} />
<Button className="m-r-5" onClick={() => this.cancel()}>
<i className="fa fa-times m-r-5" aria-hidden="true" />
Cancel
{i18next.t("Cancel")}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
{i18next.t("Cancel")}
{i18next.t("Alerts:Cancel")}

Copy link
Author

Choose a reason for hiding this comment

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

same for Cancel as for Saved., it is used in many places across the app, i did put it under the common namespace which is set as default, so we don't need to write common:

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahhhhhh ok, got it! Thanks for the explanation 🙏

</Button>
<Button type="primary" onClick={() => this.save()}>
{saving ? (
<span role="status" aria-live="polite" aria-relevant="additions removals">
<i className="fa fa-spinner fa-pulse m-r-5" aria-hidden="true" />
<span className="sr-only">Saving...</span>
<span className="sr-only">{i18next.t("Saving...")}</span>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<span className="sr-only">{i18next.t("Saving...")}</span>
<span className="sr-only">{i18next.t("Alerts:Saving")}...</span>

Copy link
Author

Choose a reason for hiding this comment

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

I will remove the three dots and other characters from the translated text in a separate PR since these Saving.. and (Help) for example are used across the app at many places... this is also why you find no namespace prefix to them since they are in the common default namespace

Setup Instructions <i className="fa fa-question-circle" aria-hidden="true" />
<span className="sr-only">(help)</span>
{i18next.t("Alerts:Setup Instructions")} <i className="fa fa-question-circle" aria-hidden="true" />
<span className="sr-only">{i18next.t("(help)")}</span>
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's nice to leave non-translatable characters like ( or ... outside of the translation string. This will make it simpler for people to add translation since they won't be worry about the context where such texts are being used.

Suggested change
<span className="sr-only">{i18next.t("(help)")}</span>
<span className="sr-only">({i18next.t("Alerts:help")})</span>

Copy link
Author

Choose a reason for hiding this comment

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

yes, (same reply as previous one :D ) I will remove the three dots and other characters from the translated text in a separate PR since these Saving.. and (Help) for example are used across the app at many places... this is also why you find no namespace prefix to them since they are in the common default namespace

@@ -79,16 +81,16 @@ export default class AlertNew extends React.Component {
{saving && (
<span role="status" aria-live="polite" aria-relevant="additions removals">
<i className="fa fa-spinner fa-pulse m-r-5" aria-hidden="true" />
<span className="sr-only">Saving...</span>
<span className="sr-only">{i18next.t("Saving...")}</span>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<span className="sr-only">{i18next.t("Saving...")}</span>
<span className="sr-only">{i18next.t("Alerts:Saving")}...</span>

Copy link
Author

@imenattatra imenattatra Jan 9, 2025

Choose a reason for hiding this comment

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

same as previous one also, thanks

<Button
data-test="ShowAddAlertSubDialog"
type="primary"
size="small"
className="add-button"
onClick={this.showAddAlertSubDialog}>
<i className="fa fa-plus f-12 m-r-5" aria-hidden="true" /> Add
<i className="fa fa-plus f-12 m-r-5" aria-hidden="true" /> {i18next.t("Add")}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<i className="fa fa-plus f-12 m-r-5" aria-hidden="true" /> {i18next.t("Add")}
<i className="fa fa-plus f-12 m-r-5" aria-hidden="true" /> {i18next.t("Alerts:Add")}

Copy link
Author

Choose a reason for hiding this comment

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

same for Add

@@ -12,6 +14,7 @@ import EllipsisOutlinedIcon from "@ant-design/icons/EllipsisOutlined";
import PlainButton from "@/components/PlainButton";

export default function MenuButton({ doDelete, canEdit, mute, unmute, muted }) {
const { t } = useTranslation();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const { t } = useTranslation();
const { t } = useTranslation("Alerts");

Copy link
Author

Choose a reason for hiding this comment

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

Here i found myself between deciding either to use const { t } = useTranslation("Alerts"); but then i will need to find a solution for many expressions that fall in the case of common namespace or just not specify the prefix earlier and specify it only when needed... I took the second decision

Comment on lines +29 to +30
title: t("Alerts:Delete Alert"),
content: t("Alerts:Are you sure you want to delete this alert?"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we've defined the t object as the translation form alerts, I feel we don't need this prefix here. Is it correct?

Suggested change
title: t("Alerts:Delete Alert"),
content: t("Alerts:Are you sure you want to delete this alert?"),
title: t("Delete Alert"),
content: t("Are you sure you want to delete this alert?"),

Copy link
Author

Choose a reason for hiding this comment

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

This is related to the previous comment

Comment on lines +53 to +55
<PlainButton onClick={() => execute(unmute)}>{t("Alerts:Unmute Notifications")}</PlainButton>
) : (
<PlainButton onClick={() => execute(mute)}>Mute Notifications</PlainButton>
<PlainButton onClick={() => execute(mute)}>{t("Alerts:Mute Notifications")}</PlainButton>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

Copy link
Author

Choose a reason for hiding this comment

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

same

Comment on lines +98 to +100
<Trans i18nKey="Alerts:just_once">
Just once <em>until back to normal</em>
</Trans>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see this as a 3rd approach on defining translations. I personally would stick with one of the previous one. If I understood it correctly, this Trans block requires this id which will be used to find the translated content. This can be harder for non-developer people to add translation because it requires they to navigate through the code to find the matching i18nKey and add the translated content.

Is this different because, within the translated context, we have this em tags?

Copy link
Author

Choose a reason for hiding this comment

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

I used Trans because it is designed for jsx code translation , so definitely it works as expected here. Also useTranslation or simple i18next.t does not work as expected with these jsx especially when it has nested content such as <em>until back to normal</em>

Copy link
Author

Choose a reason for hiding this comment

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

non developer people can check the english file, since it will include the word per word translation .. we don't have much of these cases anyway

@imenattatra
Copy link
Author

@imenattatra my comments image the time parameter is not yet translated

small think here as well when trying to add a destination and no choice is available image

do you know if there is anything we can do about these ? image

if not - please do not consider as a priority. At this time it is only a question, and does not need to be addressed in terms of implementation.

I corrected the two cases above : the time parameter and the alert destination case, but for the status, i don't want to touch it now because they are setting it from the backend but then i found out places where they check against the values, so if i touch one place and not everywhere something my stop working as it should , i prefer to do it separately later.

@imenattatra imenattatra requested a review from berinhard January 9, 2025 11:18
@imenattatra
Copy link
Author

@helenalebreton and @berinhard I created this issue so that i don't forget about alerts status and the characters in translation : https://github.com/metr-systems/backlog/issues/3722, so that I can merge this PR :D , what do you think about it?

@helenalebreton
Copy link

@helenalebreton and @berinhard I created this issue so that i don't forget about alerts status and the characters in translation : metr-systems/backlog#3722, so that I can merge this PR :D , what do you think about it?

@imenattatra please consider it no priority for now. We will take a look at it only later after we looked into other UI isseus (not linked to translation) from redash

@berinhard
Copy link
Collaborator

Nice strategy here @imenattatra. I'm good with merging this PR if pending improvements are mapped to other issues.

@imenattatra imenattatra merged commit 9dab6f2 into epic/ui-translation Jan 14, 2025
@imenattatra imenattatra deleted the add-alerts-translation branch January 14, 2025 16:30
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