From 93657909345226b056fc65e1f5c630afc011b15a Mon Sep 17 00:00:00 2001 From: artemonsh Date: Wed, 18 Jan 2023 14:20:51 +0300 Subject: [PATCH 01/16] localization --- superset/initialization/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/superset/initialization/__init__.py b/superset/initialization/__init__.py index 7e37781502313..f4df90796dcf3 100644 --- a/superset/initialization/__init__.py +++ b/superset/initialization/__init__.py @@ -330,7 +330,7 @@ def init_views(self) -> None: ) appbuilder.add_link( "SQL Editor", - label=_("SQL Lab"), + label=__("SQL Lab"), href="/superset/sqllab/", category_icon="fa-flask", icon="fa-flask", @@ -338,7 +338,8 @@ def init_views(self) -> None: category_label=__("SQL"), ) appbuilder.add_link( - __("Saved Queries"), + "Saved Queries", + label=__("Saved Queries"), href="/savedqueryview/list/", icon="fa-save", category="SQL Lab", @@ -346,7 +347,7 @@ def init_views(self) -> None: ) appbuilder.add_link( "Query Search", - label=_("Query History"), + label=__("Query History"), href="/superset/sqllab/history/", icon="fa-search", category_icon="fa-flask", @@ -385,7 +386,7 @@ def init_views(self) -> None: appbuilder.add_view( AnnotationLayerView, "Annotation Layers", - label=_("Annotation Layers"), + label=__("Annotation Layers"), href="/annotationlayer/list/", icon="fa-comment", category_icon="", @@ -406,6 +407,7 @@ def init_views(self) -> None: appbuilder.add_view( RowLevelSecurityView, "Row Level Security", + label=__("Row Level Security"), href="/rowlevelsecurity/list/", label=__("Row Level Security"), category="Security", From 6a7c86734b9635a4a7ffd61bd2dc70e4b993ef50 Mon Sep 17 00:00:00 2001 From: artemonsh Date: Wed, 18 Jan 2023 14:22:08 +0300 Subject: [PATCH 02/16] localization --- .../ColumnConfigControl/constants.tsx | 2 +- .../src/time-format/formatters/smartDate.ts | 3 +- .../formatters/smartDateDetailed.ts | 3 +- .../formatters/smartDateVerbose.ts | 3 +- .../src/Calendar.js | 5 +- .../src/Histogram.jsx | 2 +- .../src/Sunburst.js | 7 +- .../src/Radar/controlPanel.tsx | 2 +- .../src/PivotTableChart.tsx | 3 +- .../src/react-pivottable/TableRenderers.jsx | 15 ++-- .../DataTable/components/SelectPageSize.tsx | 5 +- .../src/SqlLab/actions/sqlLab.js | 5 +- .../components/QueryStateLabel/index.tsx | 5 +- .../src/SqlLab/components/ResultSet/index.tsx | 4 +- .../src/SqlLab/components/SouthPane/index.tsx | 5 +- .../src/components/DatabaseSelector/index.tsx | 3 +- .../Datasource/ChangeDatasourceModal.tsx | 2 +- .../components/Datasource/DatasourceModal.tsx | 2 + .../components/ListView/Filters/DateRange.tsx | 3 +- .../src/components/Select/Select.tsx | 2 +- .../src/dashboard/actions/dashboardState.js | 5 +- .../src/dashboard/components/SaveModal.tsx | 2 +- .../menu/BackgroundStyleDropdown.tsx | 6 +- .../FiltersConfigForm/DatasetSelect.tsx | 1 + .../FiltersConfigForm/FiltersConfigForm.tsx | 4 +- .../stylesheets/components/column.less | 1 + .../dashboard/stylesheets/components/row.less | 1 + .../src/dashboard/util/newComponentFactory.js | 2 +- superset-frontend/src/explore/constants.ts | 40 +++++---- .../getChartRequiredFieldsMissingMessage.ts | 6 +- .../src/views/CRUD/alert/AlertList.tsx | 2 +- .../src/views/CRUD/alert/AlertReportModal.tsx | 2 + .../src/views/CRUD/alert/ExecutionLog.tsx | 9 +- .../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 +-- .../annotation_layers/annotations/schemas.py | 3 +- superset/charts/post_processing.py | 7 +- superset/commands/importers/v1/__init__.py | 14 ++-- superset/connectors/base/models.py | 5 +- superset/dashboards/schemas.py | 5 +- superset/databases/schemas.py | 2 +- superset/errors.py | 84 ++++++++++--------- superset/models/sql_lab.py | 5 +- superset/reports/dao.py | 3 +- superset/sql_lab.py | 12 ++- superset/sqllab/exceptions.py | 9 +- superset/sqllab/query_render.py | 4 +- superset/utils/date_parser.py | 2 +- superset/utils/encrypt.py | 9 +- superset/utils/schema.py | 3 +- superset/views/api.py | 3 +- superset/views/dashboard/mixin.py | 2 +- superset/views/database/mixins.py | 2 +- superset/views/database/views.py | 22 ++--- superset/views/sql_lab/views.py | 2 +- superset/viz.py | 2 +- 65 files changed, 254 insertions(+), 154 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 a749e5a7cc0d7..fffadb449ac40 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 @@ -93,7 +93,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/packages/superset-ui-core/src/time-format/formatters/smartDate.ts b/superset-frontend/packages/superset-ui-core/src/time-format/formatters/smartDate.ts index 0aafb2a893cc2..92fb99c9c24f7 100644 --- a/superset-frontend/packages/superset-ui-core/src/time-format/formatters/smartDate.ts +++ b/superset-frontend/packages/superset-ui-core/src/time-format/formatters/smartDate.ts @@ -17,11 +17,12 @@ * under the License. */ +import { t } from '@superset-ui/core'; import createMultiFormatter from '../factories/createMultiFormatter'; const smartDateFormatter = createMultiFormatter({ id: 'smart_date', - label: 'Adaptative Formatting', + label: t('Adaptative Formatting'), formats: { millisecond: '.%Lms', second: ':%Ss', diff --git a/superset-frontend/packages/superset-ui-core/src/time-format/formatters/smartDateDetailed.ts b/superset-frontend/packages/superset-ui-core/src/time-format/formatters/smartDateDetailed.ts index d8a30e9a1c039..1d2ddd8f92b05 100644 --- a/superset-frontend/packages/superset-ui-core/src/time-format/formatters/smartDateDetailed.ts +++ b/superset-frontend/packages/superset-ui-core/src/time-format/formatters/smartDateDetailed.ts @@ -17,11 +17,12 @@ * under the License. */ +import { t } from '@superset-ui/core'; import createMultiFormatter from '../factories/createMultiFormatter'; const smartDateDetailedFormatter = createMultiFormatter({ id: 'smart_date_detailed', - label: 'Detailed adaptive formatter', + label: t('Detailed adaptive formatter'), formats: { millisecond: '%Y-%m-%d %H:%M:%S.%L', second: '%Y-%m-%d %H:%M:%S', diff --git a/superset-frontend/packages/superset-ui-core/src/time-format/formatters/smartDateVerbose.ts b/superset-frontend/packages/superset-ui-core/src/time-format/formatters/smartDateVerbose.ts index 4178322864bce..c309060617ca0 100644 --- a/superset-frontend/packages/superset-ui-core/src/time-format/formatters/smartDateVerbose.ts +++ b/superset-frontend/packages/superset-ui-core/src/time-format/formatters/smartDateVerbose.ts @@ -17,11 +17,12 @@ * under the License. */ +import { t } from '@superset-ui/core'; import createMultiFormatter from '../factories/createMultiFormatter'; const smartDateFormatter = createMultiFormatter({ id: 'smart_date_verbose', - label: 'Verbose Adaptative Formatting', + label: t('Verbose Adaptative Formatting'), formats: { millisecond: '.%L', second: '%a %b %d, %I:%M:%S %p', 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 0417ea3e8b5af..f120f3fa98b0b 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 = { @@ -88,7 +88,8 @@ function Calendar(element, props) { Object.keys(metricsData).forEach(metric => { const calContainer = div.append('div'); if (showMetricName) { - calContainer.text(`Metric: ${verboseMap[metric] || metric}`); + // eslint-disable-next-line prefer-template + calContainer.text(t('Metric') + `: ${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-histogram/src/Histogram.jsx b/superset-frontend/plugins/legacy-plugin-chart-histogram/src/Histogram.jsx index 2c07267748614..67d5f30f9022d 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 f967c985fcfd4..338753b678c8b 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,8 @@ 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')); if (conditionalPercString) { offsetIndex += 1; @@ -389,7 +391,8 @@ function Sunburst(element, props) { .append('text') .attr('class', 'path-cond-percent') .attr('y', yOffsets[offsetIndex]) - .text(`${conditionalPercString} of parent`); + // eslint-disable-next-line prefer-template + .text(conditionalPercString + ' ' + t('of parent')); } 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 32659bb20f613..21cd853b4636e 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Radar/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Radar/controlPanel.tsx @@ -51,7 +51,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-pivot-table/src/PivotTableChart.tsx b/superset-frontend/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx index 2063ab95dee66..2d0b463c827b0 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 ebfc4a2536640..576325a21ddec 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 989b121a3352a..48d4b9a66874e 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')}{' '}