From c839d0daf50af4e974572b3a261eae5582951bbd Mon Sep 17 00:00:00 2001 From: Artem Shumeiko <53895552+artemonsh@users.noreply.github.com> Date: Mon, 30 Jan 2023 19:20:43 +0300 Subject: [PATCH] chore: Localization of superset pt. 2 (#22772) --- .../ColumnConfigControl/constants.tsx | 2 +- .../src/Calendar.js | 6 ++- .../src/vendor/cal-heatmap.js | 8 +-- .../src/Histogram.jsx | 2 +- .../src/Sunburst.js | 8 ++- .../src/Radar/controlPanel.tsx | 2 +- .../Timeseries/Regular/Bar/controlPanel.tsx | 28 +++++----- .../src/PivotTableChart.tsx | 3 +- .../src/react-pivottable/TableRenderers.jsx | 15 +++--- .../DataTable/components/SelectPageSize.tsx | 5 +- .../plugin-chart-table/src/TableChart.tsx | 2 +- .../src/SqlLab/actions/sqlLab.js | 5 +- .../components/QueryStateLabel/index.tsx | 6 ++- .../src/SqlLab/components/ResultSet/index.tsx | 4 +- .../src/SqlLab/components/SouthPane/index.tsx | 3 +- superset-frontend/src/SqlLab/constants.ts | 20 +++++++ .../src/components/DatabaseSelector/index.tsx | 3 +- .../Datasource/ChangeDatasourceModal.tsx | 2 +- .../Datasource/DatasourceEditor.jsx | 12 ++--- .../components/Datasource/DatasourceModal.tsx | 2 + .../components/ListView/Filters/DateRange.tsx | 3 +- superset-frontend/src/constants.ts | 4 +- .../src/dashboard/actions/dashboardState.js | 5 +- .../src/dashboard/components/SaveModal.tsx | 2 +- .../menu/BackgroundStyleDropdown.tsx | 5 +- .../FiltersConfigForm/DatasetSelect.tsx | 1 + .../FiltersConfigForm/FiltersConfigForm.tsx | 4 +- .../src/dashboard/util/newComponentFactory.js | 2 +- superset-frontend/src/explore/constants.ts | 40 ++++++++------ .../src/profile/components/RecentActivity.tsx | 2 + .../getChartRequiredFieldsMissingMessage.ts | 5 +- .../src/views/CRUD/alert/AlertList.tsx | 2 +- .../src/views/CRUD/alert/AlertReportModal.tsx | 2 +- .../src/views/CRUD/alert/ExecutionLog.tsx | 12 ++++- .../views/CRUD/annotation/AnnotationModal.tsx | 1 + .../annotationlayers/AnnotationLayersList.tsx | 2 +- .../CRUD/csstemplates/CssTemplatesList.tsx | 2 +- .../DatabaseConnectionForm/EncryptedField.tsx | 4 +- .../ValidatedInputField.tsx | 6 +-- .../database/DatabaseModal/SSHTunnelForm.tsx | 4 +- .../data/database/DatabaseModal/index.tsx | 4 +- .../src/views/CRUD/data/query/QueryList.tsx | 2 +- .../CRUD/data/savedquery/SavedQueryList.tsx | 2 +- superset-frontend/src/views/CRUD/hooks.ts | 6 ++- .../src/views/CRUD/welcome/EmptyState.tsx | 13 +++-- superset/charts/post_processing.py | 7 +-- superset/connectors/base/models.py | 5 +- superset/databases/schemas.py | 2 +- superset/initialization/__init__.py | 9 ++-- superset/models/sql_lab.py | 5 +- superset/sql_lab.py | 12 ++++- superset/sqllab/exceptions.py | 9 ++-- superset/utils/date_parser.py | 2 +- superset/utils/encrypt.py | 9 +++- superset/views/api.py | 3 +- superset/views/dashboard/mixin.py | 2 +- superset/views/database/views.py | 22 ++++---- superset/views/sql_lab/views.py | 2 +- superset/viz.py | 2 +- .../unit_tests/charts/test_post_processing.py | 53 ++++++++++--------- 60 files changed, 260 insertions(+), 157 deletions(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/components/ColumnConfigControl/constants.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/components/ColumnConfigControl/constants.tsx index b940375aa9eb..ecdee5be1f28 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/components/ColumnConfigControl/constants.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/components/ColumnConfigControl/constants.tsx @@ -81,7 +81,7 @@ const columnWidth: ControlFormItemSpec<'InputNumber'> = { "Default minimal column width in pixels, actual width may still be larger than this if other columns don't need much space", ), width: 120, - placeholder: 'auto', + placeholder: t('auto'), debounceDelay: 400, validators: [validateNumber], }; diff --git a/superset-frontend/plugins/legacy-plugin-chart-calendar/src/Calendar.js b/superset-frontend/plugins/legacy-plugin-chart-calendar/src/Calendar.js index 0417ea3e8b5a..d97557a77b50 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-calendar/src/Calendar.js +++ b/superset-frontend/plugins/legacy-plugin-chart-calendar/src/Calendar.js @@ -19,7 +19,7 @@ import PropTypes from 'prop-types'; import { extent as d3Extent, range as d3Range } from 'd3-array'; import { select as d3Select } from 'd3-selection'; -import { getSequentialSchemeRegistry } from '@superset-ui/core'; +import { getSequentialSchemeRegistry, t } from '@superset-ui/core'; import CalHeatMap from './vendor/cal-heatmap'; const propTypes = { @@ -85,10 +85,12 @@ function Calendar(element, props) { const metricsData = data.data; + const METRIC_TEXT = t('Metric'); + Object.keys(metricsData).forEach(metric => { const calContainer = div.append('div'); if (showMetricName) { - calContainer.text(`Metric: ${verboseMap[metric] || metric}`); + calContainer.text(`${METRIC_TEXT}: ${verboseMap[metric] || metric}`); } const timestamps = metricsData[metric]; const extents = d3Extent(Object.keys(timestamps), key => timestamps[key]); diff --git a/superset-frontend/plugins/legacy-plugin-chart-calendar/src/vendor/cal-heatmap.js b/superset-frontend/plugins/legacy-plugin-chart-calendar/src/vendor/cal-heatmap.js index 3320693f5cc6..760bf0ce2b0c 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-calendar/src/vendor/cal-heatmap.js +++ b/superset-frontend/plugins/legacy-plugin-chart-calendar/src/vendor/cal-heatmap.js @@ -9,7 +9,7 @@ /* eslint-disable */ import d3tip from 'd3-tip'; -import { getContrastingColor } from '@superset-ui/core'; +import { getContrastingColor, t } from '@superset-ui/core'; var d3 = typeof require === 'function' ? require('d3') : window.d3; @@ -256,9 +256,9 @@ var CalHeatMap = function () { // Formatting of the title displayed when hovering a legend cell legendTitleFormat: { - lower: 'less than {min} {name}', - inner: 'between {down} and {up} {name}', - upper: 'more than {max} {name}', + lower: t('less than {min} {name}'), + inner: t('between {down} and {up} {name}'), + upper: t('more than {max} {name}'), }, // Animation duration, in ms diff --git a/superset-frontend/plugins/legacy-plugin-chart-histogram/src/Histogram.jsx b/superset-frontend/plugins/legacy-plugin-chart-histogram/src/Histogram.jsx index 2c0726774861..67d5f30f9022 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-histogram/src/Histogram.jsx +++ b/superset-frontend/plugins/legacy-plugin-chart-histogram/src/Histogram.jsx @@ -111,7 +111,7 @@ class CustomHistogram extends React.PureComponent { renderTooltip={({ datum, color }) => (
- {datum.bin0} to {datum.bin1} + {datum.bin0} {t('to')} {datum.bin1}
{t('count')} diff --git a/superset-frontend/plugins/legacy-plugin-chart-sunburst/src/Sunburst.js b/superset-frontend/plugins/legacy-plugin-chart-sunburst/src/Sunburst.js index f967c985fcfd..dd70afad3b36 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-sunburst/src/Sunburst.js +++ b/superset-frontend/plugins/legacy-plugin-chart-sunburst/src/Sunburst.js @@ -24,6 +24,7 @@ import { NumberFormats, CategoricalColorNamespace, getSequentialSchemeRegistry, + t, } from '@superset-ui/core'; import wrapSvgText from './utils/wrapSvgText'; @@ -381,7 +382,10 @@ function Sunburst(element, props) { .append('text') .attr('class', 'path-abs-percent') .attr('y', yOffsets[offsetIndex]) - .text(`${absolutePercString} of total`); + // eslint-disable-next-line prefer-template + .text(absolutePercString + ' ' + t('of total')); + + const OF_PARENT_TEXT = t('of parent'); if (conditionalPercString) { offsetIndex += 1; @@ -389,7 +393,7 @@ function Sunburst(element, props) { .append('text') .attr('class', 'path-cond-percent') .attr('y', yOffsets[offsetIndex]) - .text(`${conditionalPercString} of parent`); + .text(`${conditionalPercString} ${OF_PARENT_TEXT}`); } offsetIndex += 1; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Radar/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Radar/controlPanel.tsx index 3c320b05c4a0..68b9a17345cc 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Radar/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Radar/controlPanel.tsx @@ -50,7 +50,7 @@ const radarMetricMaxValue: { name: string; config: ControlFormItemSpec } = { 'The maximum value of metrics. It is an optional configuration', ), width: 120, - placeholder: 'auto', + placeholder: t('auto'), debounceDelay: 400, validators: [validateNumber], }, diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx index 3e1bb68f49d0..ae0dd2409c1f 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx @@ -52,7 +52,7 @@ function createAxisTitleControl(axis: 'x' | 'y'): ControlSetRow[] { const isXAxis = axis === 'x'; const isVertical = (controls: ControlStateMapping) => Boolean(controls?.orientation.value === OrientationType.vertical); - const isHorizental = (controls: ControlStateMapping) => + const isHorizontal = (controls: ControlStateMapping) => Boolean(controls?.orientation.value === OrientationType.horizontal); return [ [ @@ -65,7 +65,7 @@ function createAxisTitleControl(axis: 'x' | 'y'): ControlSetRow[] { default: '', description: t('Changing this control takes effect instantly'), visibility: ({ controls }: ControlPanelsContainerProps) => - isXAxis ? isVertical(controls) : isHorizental(controls), + isXAxis ? isVertical(controls) : isHorizontal(controls), }, }, ], @@ -82,7 +82,7 @@ function createAxisTitleControl(axis: 'x' | 'y'): ControlSetRow[] { choices: formatSelectOptions(sections.TITLE_MARGIN_OPTIONS), description: t('Changing this control takes effect instantly'), visibility: ({ controls }: ControlPanelsContainerProps) => - isXAxis ? isVertical(controls) : isHorizental(controls), + isXAxis ? isVertical(controls) : isHorizontal(controls), }, }, ], @@ -96,7 +96,7 @@ function createAxisTitleControl(axis: 'x' | 'y'): ControlSetRow[] { default: '', description: t('Changing this control takes effect instantly'), visibility: ({ controls }: ControlPanelsContainerProps) => - isXAxis ? isHorizental(controls) : isVertical(controls), + isXAxis ? isHorizontal(controls) : isVertical(controls), }, }, ], @@ -113,7 +113,7 @@ function createAxisTitleControl(axis: 'x' | 'y'): ControlSetRow[] { choices: formatSelectOptions(sections.TITLE_MARGIN_OPTIONS), description: t('Changing this control takes effect instantly'), visibility: ({ controls }: ControlPanelsContainerProps) => - isXAxis ? isHorizental(controls) : isVertical(controls), + isXAxis ? isHorizontal(controls) : isVertical(controls), }, }, ], @@ -130,7 +130,7 @@ function createAxisTitleControl(axis: 'x' | 'y'): ControlSetRow[] { choices: sections.TITLE_POSITION_OPTIONS, description: t('Changing this control takes effect instantly'), visibility: ({ controls }: ControlPanelsContainerProps) => - isXAxis ? isHorizental(controls) : isVertical(controls), + isXAxis ? isHorizontal(controls) : isVertical(controls), }, }, ], @@ -141,7 +141,7 @@ function createAxisControl(axis: 'x' | 'y'): ControlSetRow[] { const isXAxis = axis === 'x'; const isVertical = (controls: ControlStateMapping) => Boolean(controls?.orientation.value === OrientationType.vertical); - const isHorizental = (controls: ControlStateMapping) => + const isHorizontal = (controls: ControlStateMapping) => Boolean(controls?.orientation.value === OrientationType.horizontal); return [ [ @@ -154,7 +154,7 @@ function createAxisControl(axis: 'x' | 'y'): ControlSetRow[] { 'When using other than adaptive formatting, labels may overlap.', )}`, visibility: ({ controls }: ControlPanelsContainerProps) => - isXAxis ? isVertical(controls) : isHorizental(controls), + isXAxis ? isVertical(controls) : isHorizontal(controls), }, }, ], @@ -176,7 +176,7 @@ function createAxisControl(axis: 'x' | 'y'): ControlSetRow[] { 'Input field supports custom rotation. e.g. 30 for 30°', ), visibility: ({ controls }: ControlPanelsContainerProps) => - isXAxis ? isVertical(controls) : isHorizental(controls), + isXAxis ? isVertical(controls) : isHorizontal(controls), }, }, ], @@ -187,7 +187,7 @@ function createAxisControl(axis: 'x' | 'y'): ControlSetRow[] { ...sharedControls.y_axis_format, label: t('Axis Format'), visibility: ({ controls }: ControlPanelsContainerProps) => - isXAxis ? isHorizental(controls) : isVertical(controls), + isXAxis ? isHorizontal(controls) : isVertical(controls), }, }, ], @@ -201,7 +201,7 @@ function createAxisControl(axis: 'x' | 'y'): ControlSetRow[] { default: logAxis, description: t('Logarithmic axis'), visibility: ({ controls }: ControlPanelsContainerProps) => - isXAxis ? isHorizental(controls) : isVertical(controls), + isXAxis ? isHorizontal(controls) : isVertical(controls), }, }, ], @@ -215,7 +215,7 @@ function createAxisControl(axis: 'x' | 'y'): ControlSetRow[] { default: minorSplitLine, description: t('Draw split lines for minor axis ticks'), visibility: ({ controls }: ControlPanelsContainerProps) => - isXAxis ? isHorizental(controls) : isVertical(controls), + isXAxis ? isHorizontal(controls) : isVertical(controls), }, }, ], @@ -229,7 +229,7 @@ function createAxisControl(axis: 'x' | 'y'): ControlSetRow[] { renderTrigger: true, description: t('It’s not recommended to truncate axis in Bar chart.'), visibility: ({ controls }: ControlPanelsContainerProps) => - isXAxis ? isHorizental(controls) : isVertical(controls), + isXAxis ? isHorizontal(controls) : isVertical(controls), }, }, ], @@ -249,7 +249,7 @@ function createAxisControl(axis: 'x' | 'y'): ControlSetRow[] { ), visibility: ({ controls }: ControlPanelsContainerProps) => Boolean(controls?.truncateYAxis?.value) && - (isXAxis ? isHorizental(controls) : isVertical(controls)), + (isXAxis ? isHorizontal(controls) : isVertical(controls)), }, }, ], diff --git a/superset-frontend/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx b/superset-frontend/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx index a5feed70f21b..d9653686e11d 100644 --- a/superset-frontend/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx +++ b/superset-frontend/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx @@ -29,6 +29,7 @@ import { useTheme, isAdhocColumn, BinaryQueryObjectFilterClause, + t, } from '@superset-ui/core'; import { PivotTable, sortAs, aggregatorTemplates } from './react-pivottable'; import { @@ -55,7 +56,7 @@ const PivotTableWrapper = styled.div` overflow: auto; `; -const METRIC_KEY = 'metric'; +const METRIC_KEY = t('metric'); const vals = ['value']; const StyledPlusSquareOutlined = styled(PlusSquareOutlined)` diff --git a/superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/TableRenderers.jsx b/superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/TableRenderers.jsx index ebfc4a253664..576325a21dde 100644 --- a/superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/TableRenderers.jsx +++ b/superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/TableRenderers.jsx @@ -487,7 +487,9 @@ export class TableRenderer extends React.Component { true, )} > - {`Total (${this.props.aggregatorName})`} + {t('Total (%(aggregatorName)s)', { + aggregatorName: t(this.props.aggregatorName), + })} ) : null; @@ -550,7 +552,9 @@ export class TableRenderer extends React.Component { )} > {colAttrs.length === 0 - ? `Total (${this.props.aggregatorName})` + ? t('Total (%(aggregatorName)s)', { + aggregatorName: t(this.props.aggregatorName), + }) : null} @@ -764,10 +768,9 @@ export class TableRenderer extends React.Component { true, )} > - { - // eslint-disable-next-line prefer-template - t('Total') + ` (${this.props.aggregatorName})` - } + {t('Total (%(aggregatorName)s)', { + aggregatorName: t(this.props.aggregatorName), + })} ); diff --git a/superset-frontend/plugins/plugin-chart-table/src/DataTable/components/SelectPageSize.tsx b/superset-frontend/plugins/plugin-chart-table/src/DataTable/components/SelectPageSize.tsx index 989b121a3352..48d4b9a66874 100644 --- a/superset-frontend/plugins/plugin-chart-table/src/DataTable/components/SelectPageSize.tsx +++ b/superset-frontend/plugins/plugin-chart-table/src/DataTable/components/SelectPageSize.tsx @@ -17,6 +17,7 @@ * under the License. */ import React from 'react'; +import { t } from '@superset-ui/core'; import { formatSelectOptions } from '@superset-ui/chart-controls'; export type SizeOption = [number, string]; @@ -34,7 +35,7 @@ function DefaultSelectRenderer({ }: SelectPageSizeRendererProps) { return ( - Show{' '} + {t('Show')}{' '}