diff --git a/frontend/public/components/monitoring/dashboards/index.tsx b/frontend/public/components/monitoring/dashboards/index.tsx index 375da74b81e..b0d2f3dd70a 100644 --- a/frontend/public/components/monitoring/dashboards/index.tsx +++ b/frontend/public/components/monitoring/dashboards/index.tsx @@ -2,6 +2,7 @@ import * as _ from 'lodash-es'; import { Dropdown, DropdownToggle, DropdownItem } from '@patternfly/react-core'; import * as React from 'react'; import { Helmet } from 'react-helmet'; +import { useTranslation } from 'react-i18next'; import { connect } from 'react-redux'; import { Map as ImmutableMap } from 'immutable'; @@ -70,6 +71,8 @@ const VariableDropdown: React.FC = ({ onChange, selectedKey, }) => { + const { t } = useTranslation(); + const [isOpen, toggleIsOpen, , setClosed] = useBoolean(false); return ( @@ -79,7 +82,7 @@ const VariableDropdown: React.FC = ({ - Error loading options + {t('monitoring~Error loading options')} } /> @@ -201,29 +204,31 @@ const AllVariableDropdowns = connect(({ UI }: RootState) => ({ variables: UI.getIn(['monitoringDashboards', 'variables']), }))(AllVariableDropdowns_); -const timespanOptions = { - '5m': '5 minutes', - '15m': '15 minutes', - '30m': '30 minutes', - '1h': '1 hour', - '2h': '2 hours', - '6h': '6 hours', - '12h': '12 hours', - '1d': '1 day', - '2d': '2 days', - '1w': '1 week', - '2w': '2 weeks', -}; - const TimespanDropdown_: React.FC = ({ timespan, setTimespan }) => { + const { t } = useTranslation(); + const onChange = React.useCallback((v: string) => setTimespan(parsePrometheusDuration(v)), [ setTimespan, ]); + const timespanOptions = { + '5m': t('monitoring~{{count}} minute', { count: 5 }), + '15m': t('monitoring~{{count}} minute', { count: 15 }), + '30m': t('monitoring~{{count}} minute', { count: 30 }), + '1h': t('monitoring~{{count}} hour', { count: 1 }), + '2h': t('monitoring~{{count}} hour', { count: 2 }), + '6h': t('monitoring~{{count}} hour', { count: 6 }), + '12h': t('monitoring~{{count}} hour', { count: 12 }), + '1d': t('monitoring~{{count}} day', { count: 1 }), + '2d': t('monitoring~{{count}} day', { count: 2 }), + '1w': t('monitoring~{{count}} week', { count: 1 }), + '2w': t('monitoring~{{count}} week', { count: 2 }), + }; + return ( @@ -239,12 +244,18 @@ export const TimespanDropdown = connect( }, )(TimespanDropdown_); -const PollIntervalDropdown_ = ({ interval, setInterval }) => ( -
- - -
-); +const PollIntervalDropdown_ = ({ interval, setInterval }) => { + const { t } = useTranslation(); + + return ( +
+ + +
+ ); +}; export const PollIntervalDropdown = connect( ({ UI }: RootState) => ({ @@ -405,6 +416,8 @@ const MonitoringDashboardsPage_: React.FC = ({ match, patchAllVariables, }) => { + const { t } = useTranslation(); + const [board, setBoard] = React.useState(); const [boards, setBoards] = React.useState([]); const [error, setError] = React.useState(); @@ -428,7 +441,11 @@ const MonitoringDashboardsPage_: React.FC = ({ name: item.metadata.name, }; } catch (e) { - setError(`Could not parse JSON data for dashboard "${item.metadata.name}"`); + setError( + t('monitoring~Could not parse JSON data for dashboard "{{dashboard}}"', { + dashboard: item.metadata.name, + }), + ); } }; @@ -443,7 +460,7 @@ const MonitoringDashboardsPage_: React.FC = ({ setError(_.get(err, 'json.error', err.message)); } }); - }, [safeFetch, setLoaded]); + }, [safeFetch, setLoaded, t]); const boardItems = React.useMemo(() => _.mapValues(_.mapKeys(boards, 'name'), 'data.title'), [ boards, @@ -492,13 +509,13 @@ const MonitoringDashboardsPage_: React.FC = ({ return ( <> - Metrics Dashboards + {t('monitoring~Metrics dashboards')}

- Dashboards + {t('monitoring~Dashboards')}

@@ -510,7 +527,7 @@ const MonitoringDashboardsPage_: React.FC = ({ {!_.isEmpty(boardItems) && ( diff --git a/frontend/public/components/monitoring/metrics.tsx b/frontend/public/components/monitoring/metrics.tsx index e1208d0acf5..bdcd2daf0f1 100644 --- a/frontend/public/components/monitoring/metrics.tsx +++ b/frontend/public/components/monitoring/metrics.tsx @@ -149,18 +149,22 @@ const MetricsActionsMenu_: React.FC = ({ isAllExpanded, setAllExpanded, }) => { + const { t } = useTranslation(); + const doDelete = () => { deleteAll(); focusedQuery = undefined; }; const actionsMenuActions = [ - { label: 'Add query', callback: addQuery }, + { label: t('monitoring~Add query'), callback: addQuery }, { - label: `${isAllExpanded ? 'Collapse' : 'Expand'} all query tables`, + label: isAllExpanded + ? t('monitoring~Collapse all query tables') + : t('monitoring~Expand all query tables'), callback: () => setAllExpanded(!isAllExpanded), }, - { label: 'Delete all queries', callback: doDelete }, + { label: t('monitoring~Delete all queries'), callback: doDelete }, ]; return ( @@ -208,6 +212,7 @@ const graphStateToProps = ({ UI }: RootState) => ({ const ToggleGraph_ = ({ hideGraphs, toggle }) => { const { t } = useTranslation(); + const icon = hideGraphs ? : ; return ( @@ -226,6 +231,8 @@ export const ToggleGraph = connect(graphStateToProps, { toggle: UIActions.monito ); const MetricsDropdown_: React.FC = ({ insertText, setMetrics }) => { + const { t } = useTranslation(); + const [items, setItems] = React.useState(); const [error, setError] = React.useState(); @@ -258,7 +265,7 @@ const MetricsDropdown_: React.FC = ({ insertText, setMetri } }; - let title: React.ReactNode = 'Insert Metric at Cursor'; + let title: React.ReactNode = t('monitoring~Insert metric at cursor'); if (error !== undefined) { const message = error?.response?.status === 403 ? 'Access restricted.' : 'Failed to load metrics list.'; @@ -396,6 +403,8 @@ const QueryInput_: React.FC = ({ runQueries, text = '', }) => { + const { t } = useTranslation(); + const [token, setToken] = React.useState(''); const inputRef = React.useRef(null); @@ -487,16 +496,18 @@ const QueryInput_: React.FC = ({ // Set the default textarea height to the number of lines in the query text const rows = _.clamp((text.match(/\n/g) || []).length + 1, 2, 10); + const placeholder = t('monitoring~Expression (press Shift+Enter for newlines)'); + return (