Skip to content

Commit

Permalink
Added i18n translations
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Oct 2, 2020
1 parent 64cf479 commit 5814739
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { PLUGIN } from '../../../constants/plugin';
import { AlertEdit } from '../../alert_form';
import { AlertsContextProvider } from '../../../context/alerts_context';
import { routeToAlertDetails } from '../../../constants';
import { alertsErrorReasonTranslationsMapping } from '../../alerts_list/translations';

type AlertDetailsProps = {
alert: Alert;
Expand Down Expand Up @@ -113,10 +114,10 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
};

const getAlertStatusErrorReasonText = () => {
if (alert.executionStatus.error && alert.executionStatus.error.reason !== 'unknown') {
return `An error occurred when ${alert.executionStatus.error.reason} the alert.`;
if (alert.executionStatus.error && alert.executionStatus.error.reason) {
return alertsErrorReasonTranslationsMapping[alert.executionStatus.error.reason];
} else {
return 'An error occurred for unknown reasons.';
return alertsErrorReasonTranslationsMapping.unknown;
}
};

Expand Down Expand Up @@ -292,12 +293,7 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
color="danger"
data-test-subj="alertErrorBanner"
size="s"
title={i18n.translate(
'xpack.triggersActionsUI.sections.alertDetails.attentionBannerTitle',
{
defaultMessage: `${getAlertStatusErrorReasonText()}`,
}
)}
title={getAlertStatusErrorReasonText()}
iconType="alert"
>
<EuiText size="s" color="danger" data-test-subj="alertErrorMessageText">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
AlertExecutionStatuses,
AlertExecutionStatusValues,
} from '../../../../../../alerts/common';
import { alertsStatusesTranslationsMapping } from '../translations';

interface AlertStatusFilterProps {
selectedStatuses: string[];
Expand Down Expand Up @@ -78,7 +79,7 @@ export const AlertStatusFilter: React.FunctionComponent<AlertStatusFilterProps>
}}
checked={selectedValues.includes(item) ? 'on' : undefined}
>
<EuiHealth color={healthColor}>{item}</EuiHealth>
<EuiHealth color={healthColor}>{alertsStatusesTranslationsMapping[item]}</EuiHealth>
</EuiFilterSelectItem>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
ALERTS_FEATURE_ID,
} from '../../../../../../alerts/common';
import { hasAllPrivilege } from '../../../lib/capabilities';
import { alertsStatusesTranslationsMapping } from '../translations';

const ENTER_KEY = 13;

Expand Down Expand Up @@ -240,7 +241,7 @@ export const AlertsList: React.FunctionComponent = () => {
const healthColor = getHealthColor(executionStatus.status);
return (
<EuiHealth data-test-subj={`alertStatus-${executionStatus.status}`} color={healthColor}>
{executionStatus.status}
{alertsStatusesTranslationsMapping[executionStatus.status]}
</EuiHealth>
);
},
Expand Down Expand Up @@ -498,7 +499,7 @@ export const AlertsList: React.FunctionComponent = () => {
<FormattedMessage
id="xpack.triggersActionsUI.sections.alertsList.totalStausesErrorDescription"
data-test-subj="totalStausesError"
defaultMessage="Errors: {totalStausesError}"
defaultMessage="Error: {totalStausesError}"
values={{ totalStausesError: alertsStatusesTotal.error }}
/>
</EuiHealth>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { i18n } from '@kbn/i18n';

export const ALERT_STATUS_OK = i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertStatusOk',
{
defaultMessage: 'Ok',
}
);

export const ALERT_STATUS_ACTIVE = i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertStatusActive',
{
defaultMessage: 'Active',
}
);

export const ALERT_STATUS_ERROR = i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertStatusError',
{
defaultMessage: 'Error',
}
);

export const ALERT_STATUS_PENDING = i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertStatusPending',
{
defaultMessage: 'Pending',
}
);

export const ALERT_STATUS_UNKNOWN = i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertStatusUnknown',
{
defaultMessage: 'Unknown',
}
);

export const alertsStatusesTranslationsMapping = {
ok: ALERT_STATUS_OK,
active: ALERT_STATUS_ACTIVE,
error: ALERT_STATUS_ERROR,
pending: ALERT_STATUS_PENDING,
unknown: ALERT_STATUS_UNKNOWN,
};

export const ALERT_ERROR_UNKNOWN_REASON = i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertErrorReasonUnknown',
{
defaultMessage: 'An error occurred for unknown reasons.',
}
);

export const ALERT_ERROR_READING_REASON = i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertErrorReasonReading',
{
defaultMessage: 'An error occurred when reading the alert.',
}
);

export const ALERT_ERROR_DECRYPTING_REASON = i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertErrorReasonDecrypting',
{
defaultMessage: 'An error occurred when decrypting the alert.',
}
);

export const ALERT_ERROR_EXECUTION_REASON = i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertErrorReasonRunning',
{
defaultMessage: 'An error occurred when running the alert.',
}
);

export const alertsErrorReasonTranslationsMapping = {
read: ALERT_ERROR_READING_REASON,
decrypt: ALERT_ERROR_DECRYPTING_REASON,
execute: ALERT_ERROR_EXECUTION_REASON,
unknown: ALERT_ERROR_UNKNOWN_REASON,
};

0 comments on commit 5814739

Please sign in to comment.