mirror of
https://github.com/grafana/grafana.git
synced 2026-07-30 00:08:10 -05:00
Internationalization: Translate TimeRangePicker component (#58470)
This commit is contained in:
@@ -27,6 +27,6 @@ describe('TimePicker', () => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(container.queryByLabelText(/Time range picker/i)).toBeInTheDocument();
|
expect(container.queryByLabelText(/Time range selected/i)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
import { selectors } from '@grafana/e2e-selectors';
|
import { selectors } from '@grafana/e2e-selectors';
|
||||||
|
|
||||||
import { useStyles2 } from '../../themes/ThemeContext';
|
import { useStyles2 } from '../../themes/ThemeContext';
|
||||||
|
import { t, Trans } from '../../utils/i18n';
|
||||||
import { ButtonGroup } from '../Button';
|
import { ButtonGroup } from '../Button';
|
||||||
import { ToolbarButton } from '../ToolbarButton';
|
import { ToolbarButton } from '../ToolbarButton';
|
||||||
import { Tooltip } from '../Tooltip/Tooltip';
|
import { Tooltip } from '../Tooltip/Tooltip';
|
||||||
@@ -91,11 +92,13 @@ export function TimeRangePicker(props: TimeRangePickerProps) {
|
|||||||
const hasAbsolute = isDateTime(value.raw.from) || isDateTime(value.raw.to);
|
const hasAbsolute = isDateTime(value.raw.from) || isDateTime(value.raw.to);
|
||||||
const variant = isSynced ? 'active' : isOnCanvas ? 'canvas' : 'default';
|
const variant = isSynced ? 'active' : isOnCanvas ? 'canvas' : 'default';
|
||||||
|
|
||||||
|
const currentTimeRange = formattedRange(value, timeZone);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ButtonGroup className={styles.container}>
|
<ButtonGroup className={styles.container}>
|
||||||
{hasAbsolute && (
|
{hasAbsolute && (
|
||||||
<ToolbarButton
|
<ToolbarButton
|
||||||
aria-label="Move time range backwards"
|
aria-label={t('time-picker.range-picker.backwards-time-aria-label', 'Move time range backwards')}
|
||||||
variant={variant}
|
variant={variant}
|
||||||
onClick={onMoveBackward}
|
onClick={onMoveBackward}
|
||||||
icon="angle-left"
|
icon="angle-left"
|
||||||
@@ -106,7 +109,9 @@ export function TimeRangePicker(props: TimeRangePickerProps) {
|
|||||||
<Tooltip content={<TimePickerTooltip timeRange={value} timeZone={timeZone} />} placement="bottom" interactive>
|
<Tooltip content={<TimePickerTooltip timeRange={value} timeZone={timeZone} />} placement="bottom" interactive>
|
||||||
<ToolbarButton
|
<ToolbarButton
|
||||||
data-testid={selectors.components.TimePicker.openButton}
|
data-testid={selectors.components.TimePicker.openButton}
|
||||||
aria-label={`Time range picker with current time range ${formattedRange(value, timeZone)} selected`}
|
aria-label={t('time-picker.range-picker.current-time-selected', 'Time range selected: {{currentTimeRange}}', {
|
||||||
|
currentTimeRange,
|
||||||
|
})}
|
||||||
aria-controls="TimePickerContent"
|
aria-controls="TimePickerContent"
|
||||||
onClick={onOpen}
|
onClick={onOpen}
|
||||||
icon="clock-nine"
|
icon="clock-nine"
|
||||||
@@ -140,7 +145,7 @@ export function TimeRangePicker(props: TimeRangePickerProps) {
|
|||||||
|
|
||||||
{hasAbsolute && (
|
{hasAbsolute && (
|
||||||
<ToolbarButton
|
<ToolbarButton
|
||||||
aria-label="Move time range forwards"
|
aria-label={t('time-picker.range-picker.forwards-time-aria-label', 'Move time range forwards')}
|
||||||
onClick={onMoveForward}
|
onClick={onMoveForward}
|
||||||
icon="angle-right"
|
icon="angle-right"
|
||||||
narrow
|
narrow
|
||||||
@@ -149,7 +154,12 @@ export function TimeRangePicker(props: TimeRangePickerProps) {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<Tooltip content={ZoomOutTooltip} placement="bottom">
|
<Tooltip content={ZoomOutTooltip} placement="bottom">
|
||||||
<ToolbarButton aria-label="Zoom out time range" onClick={onZoom} icon="search-minus" variant={variant} />
|
<ToolbarButton
|
||||||
|
aria-label={t('time-picker.range-picker.zoom-out-button', 'Zoom out time range')}
|
||||||
|
onClick={onZoom}
|
||||||
|
icon="search-minus"
|
||||||
|
variant={variant}
|
||||||
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
);
|
);
|
||||||
@@ -159,7 +169,9 @@ TimeRangePicker.displayName = 'TimeRangePicker';
|
|||||||
|
|
||||||
const ZoomOutTooltip = () => (
|
const ZoomOutTooltip = () => (
|
||||||
<>
|
<>
|
||||||
Time range zoom out <br /> CTRL+Z
|
<Trans i18nKey="time-picker.range-picker.zoom-out-tooltip">
|
||||||
|
Time range zoom out <br /> CTRL+Z
|
||||||
|
</Trans>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -169,7 +181,9 @@ const TimePickerTooltip = ({ timeRange, timeZone }: { timeRange: TimeRange; time
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{dateTimeFormat(timeRange.from, { timeZone })}
|
{dateTimeFormat(timeRange.from, { timeZone })}
|
||||||
<div className="text-center">to</div>
|
<div className="text-center">
|
||||||
|
<Trans i18nKey="time-picker.range-picker.to">to</Trans>
|
||||||
|
</div>
|
||||||
{dateTimeFormat(timeRange.to, { timeZone })}
|
{dateTimeFormat(timeRange.to, { timeZone })}
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
<span className={styles.utc}>{timeZoneFormatUserFriendly(timeZone)}</span>
|
<span className={styles.utc}>{timeZoneFormatUserFriendly(timeZone)}</span>
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export const Trans: typeof I18NextTrans = (props) => {
|
|||||||
return <I18NextTrans {...props} />;
|
return <I18NextTrans {...props} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const t = (id: string, defaultMessage: string) => {
|
export const t = (id: string, defaultMessage: string, values?: Record<string, unknown>) => {
|
||||||
initI18n();
|
initI18n();
|
||||||
return i18next.t(id, defaultMessage);
|
return i18next.t(id, defaultMessage, values);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -436,6 +436,14 @@
|
|||||||
"range-error": "",
|
"range-error": "",
|
||||||
"to-input": ""
|
"to-input": ""
|
||||||
},
|
},
|
||||||
|
"range-picker": {
|
||||||
|
"backwards-time-aria-label": "",
|
||||||
|
"current-time-selected": "",
|
||||||
|
"forwards-time-aria-label": "",
|
||||||
|
"to": "",
|
||||||
|
"zoom-out-button": "",
|
||||||
|
"zoom-out-tooltip": ""
|
||||||
|
},
|
||||||
"time-range": {
|
"time-range": {
|
||||||
"aria-role": "",
|
"aria-role": "",
|
||||||
"default-title": "",
|
"default-title": "",
|
||||||
|
|||||||
@@ -436,6 +436,14 @@
|
|||||||
"range-error": "\"From\" can't be after \"To\"",
|
"range-error": "\"From\" can't be after \"To\"",
|
||||||
"to-input": "To"
|
"to-input": "To"
|
||||||
},
|
},
|
||||||
|
"range-picker": {
|
||||||
|
"backwards-time-aria-label": "Move time range backwards",
|
||||||
|
"current-time-selected": "Time range selected: {{currentTimeRange}}",
|
||||||
|
"forwards-time-aria-label": "Move time range forwards",
|
||||||
|
"to": "to",
|
||||||
|
"zoom-out-button": "Zoom out time range",
|
||||||
|
"zoom-out-tooltip": "Time range zoom out <1></1> CTRL+Z"
|
||||||
|
},
|
||||||
"time-range": {
|
"time-range": {
|
||||||
"aria-role": "Time range selection",
|
"aria-role": "Time range selection",
|
||||||
"default-title": "Time ranges",
|
"default-title": "Time ranges",
|
||||||
|
|||||||
@@ -436,6 +436,14 @@
|
|||||||
"range-error": "",
|
"range-error": "",
|
||||||
"to-input": ""
|
"to-input": ""
|
||||||
},
|
},
|
||||||
|
"range-picker": {
|
||||||
|
"backwards-time-aria-label": "",
|
||||||
|
"current-time-selected": "",
|
||||||
|
"forwards-time-aria-label": "",
|
||||||
|
"to": "",
|
||||||
|
"zoom-out-button": "",
|
||||||
|
"zoom-out-tooltip": ""
|
||||||
|
},
|
||||||
"time-range": {
|
"time-range": {
|
||||||
"aria-role": "",
|
"aria-role": "",
|
||||||
"default-title": "",
|
"default-title": "",
|
||||||
|
|||||||
@@ -436,6 +436,14 @@
|
|||||||
"range-error": "",
|
"range-error": "",
|
||||||
"to-input": ""
|
"to-input": ""
|
||||||
},
|
},
|
||||||
|
"range-picker": {
|
||||||
|
"backwards-time-aria-label": "",
|
||||||
|
"current-time-selected": "",
|
||||||
|
"forwards-time-aria-label": "",
|
||||||
|
"to": "",
|
||||||
|
"zoom-out-button": "",
|
||||||
|
"zoom-out-tooltip": ""
|
||||||
|
},
|
||||||
"time-range": {
|
"time-range": {
|
||||||
"aria-role": "",
|
"aria-role": "",
|
||||||
"default-title": "",
|
"default-title": "",
|
||||||
|
|||||||
@@ -436,6 +436,14 @@
|
|||||||
"range-error": "\"Fřőm\" čäʼn'ŧ þę äƒŧęř \"Ŧő\"",
|
"range-error": "\"Fřőm\" čäʼn'ŧ þę äƒŧęř \"Ŧő\"",
|
||||||
"to-input": "Ŧő"
|
"to-input": "Ŧő"
|
||||||
},
|
},
|
||||||
|
"range-picker": {
|
||||||
|
"backwards-time-aria-label": "Mővę ŧįmę řäʼnģę þäčĸŵäřđş",
|
||||||
|
"current-time-selected": "Ŧįmę řäʼnģę şęľęčŧęđ: {{čūřřęʼnŧŦįmęŖäʼnģę}}",
|
||||||
|
"forwards-time-aria-label": "Mővę ŧįmę řäʼnģę ƒőřŵäřđş",
|
||||||
|
"to": "ŧő",
|
||||||
|
"zoom-out-button": "Żőőm őūŧ ŧįmę řäʼnģę",
|
||||||
|
"zoom-out-tooltip": "Ŧįmę řäʼnģę žőőm őūŧ <1></1> CŦŖĿ+Ż"
|
||||||
|
},
|
||||||
"time-range": {
|
"time-range": {
|
||||||
"aria-role": "Ŧįmę řäʼnģę şęľęčŧįőʼn",
|
"aria-role": "Ŧįmę řäʼnģę şęľęčŧįőʼn",
|
||||||
"default-title": "Ŧįmę řäʼnģęş",
|
"default-title": "Ŧįmę řäʼnģęş",
|
||||||
|
|||||||
@@ -436,6 +436,14 @@
|
|||||||
"range-error": "",
|
"range-error": "",
|
||||||
"to-input": ""
|
"to-input": ""
|
||||||
},
|
},
|
||||||
|
"range-picker": {
|
||||||
|
"backwards-time-aria-label": "",
|
||||||
|
"current-time-selected": "",
|
||||||
|
"forwards-time-aria-label": "",
|
||||||
|
"to": "",
|
||||||
|
"zoom-out-button": "",
|
||||||
|
"zoom-out-tooltip": ""
|
||||||
|
},
|
||||||
"time-range": {
|
"time-range": {
|
||||||
"aria-role": "",
|
"aria-role": "",
|
||||||
"default-title": "",
|
"default-title": "",
|
||||||
|
|||||||
Reference in New Issue
Block a user