Skip to content

Commit 958109f

Browse files
committed
localize a whole lotta stuff
1 parent 48b04bd commit 958109f

File tree

8 files changed

+312
-198
lines changed

8 files changed

+312
-198
lines changed

scripts/translationKeys/combined-translation-keys.txt

Lines changed: 122 additions & 86 deletions
Large diffs are not rendered by default.

scripts/translationKeys/translation-keys.txt

Lines changed: 122 additions & 86 deletions
Large diffs are not rendered by default.

src/PlotlyEditor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import DefaultEditor from './DefaultEditor';
22
import PropTypes from 'prop-types';
33
import React, {Component} from 'react';
4-
import dictionaries from './locales';
54
import {bem} from './lib';
65
import {noShame, maybeClearAxisTypes} from './shame';
76
import {EDITOR_ACTIONS} from './lib/constants';
@@ -40,7 +39,7 @@ class PlotlyEditor extends Component {
4039
dataSourceOptions: this.props.dataSourceOptions,
4140
dataSourceValueRenderer: this.props.dataSourceValueRenderer,
4241
dataSourceOptionRenderer: this.props.dataSourceOptionRenderer,
43-
dictionaries: dictionaries,
42+
dictionaries: this.props.dictionaries || {},
4443
fullData: gd._fullData,
4544
fullLayout: gd._fullLayout,
4645
graphDiv: gd,
@@ -159,6 +158,7 @@ PlotlyEditor.propTypes = {
159158
dataSourceOptions: PropTypes.array,
160159
dataSourceValueRenderer: PropTypes.func,
161160
dataSourceOptionRenderer: PropTypes.func,
161+
dictionaries: PropTypes.object,
162162
graphDiv: PropTypes.object,
163163
locale: PropTypes.string,
164164
revision: PropTypes.any,

src/components/containers/PanelHeader.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ class PanelHeader extends Component {
3232
}
3333

3434
render() {
35-
const {children, action, allowCollapse, toggleFolds, hasOpen} = this.props;
35+
const {
36+
children,
37+
action,
38+
allowCollapse,
39+
toggleFolds,
40+
hasOpen,
41+
localize: _
42+
} = this.props;
43+
3644
return !children && !action && !allowCollapse ? null : (
3745
<div className="panel__header">
3846
{children && children.length ? (
@@ -44,12 +52,12 @@ class PanelHeader extends Component {
4452
{hasOpen ? (
4553
<span>
4654
<ResizeDownIcon />
47-
Collapse All
55+
{_('Collapse All')}
4856
</span>
4957
) : (
5058
<span>
5159
<ResizeUpIcon />
52-
Expand All
60+
{_('Expand All')}
5361
</span>
5462
)}
5563
</div>

src/components/fields/TraceSelector.js

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,54 @@ import {
55
capitalize,
66
connectToContainer,
77
customTraceToPlotlyTrace,
8+
localize,
89
plotlyTraceToCustomTrace,
910
} from 'lib';
1011

11-
function computeTraceOptionsFromSchema(schema) {
12+
function computeTraceOptionsFromSchema(schema, _) {
1213
// Filter out Polar "area" type as it is fairly broken and we want to present
1314
// scatter with fill as an "area" chart type for convenience.
1415
const traceTypes = Object.keys(schema.traces).filter(t => t !== 'area');
1516

16-
const labels = traceTypes.map(capitalize);
17-
const traceOptions = traceTypes.map((t, i) => ({
18-
label: labels[i],
19-
value: t,
20-
}));
17+
// explicit map of all supported trace types (as of plotlyjs 1.32)
18+
const traceOptions = [
19+
{value: 'scatter', label: _('Scatter')},
20+
{value: 'box', label: _('Box')},
21+
{value: 'bar', label: _('Bar')},
22+
{value: 'heatmap', label: _('Heatmap')},
23+
{value: 'histogram', label: _('Histogram')},
24+
{value: 'histogram2d', label: _('2D Histogram')},
25+
{value: 'histogram2dcontour', label: _('2D Contour Histogram')},
26+
{value: 'pie', label: _('Pie')},
27+
{value: 'contour', label: _('Contour')},
28+
{value: 'scatterternary', label: _('Ternary Scatter')},
29+
{value: 'violin', label: _('Violin')},
30+
{value: 'scatter3d', label: _('3D Scatter')},
31+
{value: 'surface', label: _('Surface')},
32+
{value: 'mesh3d', label: _('Mesh3d')},
33+
{value: 'scattergeo', label: _('Atlas Map')},
34+
{value: 'choropleth', label: _('Choropleth')},
35+
{value: 'scattergl', label: _('Scatter GL')},
36+
{value: 'pointcloud', label: _('Point Cloud')},
37+
{value: 'heatmapgl', label: _('Heatmap GL')},
38+
{value: 'parcoords', label: _('Parallel Coordinates')},
39+
{value: 'scattermapbox', label: _('Satellite Map')},
40+
{value: 'sankey', label: _('Sankey')},
41+
{value: 'table', label: _('Table')},
42+
{value: 'carpet', label: _('Carpet')},
43+
{value: 'scattercarpet', label: _('Carpet Scatter')},
44+
{value: 'contourcarpet', label: _('Carpet Contour')},
45+
{value: 'ohlc', label: _('OHLC')},
46+
{value: 'candlestick', label: _('Candlestick')},
47+
{value: 'scatterpolar', label: _('Polar Scatter')},
48+
].filter(obj => traceTypes.indexOf(obj.value) !== -1);
2149

2250
const i = traceOptions.findIndex(opt => opt.value === 'scatter');
2351
traceOptions.splice(
2452
i + 1,
2553
0,
26-
{label: 'Line', value: 'line'},
27-
{label: 'Area', value: 'area'}
54+
{label: _('Line'), value: 'line'},
55+
{label: _('Area'), value: 'area'}
2856
);
2957

3058
return traceOptions;
@@ -60,12 +88,13 @@ class TraceSelector extends Component {
6088
}
6189

6290
setLocals(props, context) {
91+
const _ = props.localize;
6392
if (props.traceOptions) {
6493
this.traceOptions = props.traceOptions;
6594
} else if (context.plotSchema) {
66-
this.traceOptions = computeTraceOptionsFromSchema(context.plotSchema);
95+
this.traceOptions = computeTraceOptionsFromSchema(context.plotSchema, _);
6796
} else {
68-
this.traceOptions = [{label: 'Scatter', value: 'scatter'}];
97+
this.traceOptions = [{label: _('Scatter'), value: 'scatter'}];
6998
}
7099
this.fullValue = plotlyTraceToCustomTrace(props.container);
71100
}
@@ -112,7 +141,8 @@ TraceSelector.propTypes = {
112141
container: PropTypes.object.isRequired,
113142
fullContainer: PropTypes.object.isRequired,
114143
fullValue: PropTypes.any.isRequired,
144+
localize: PropTypes.func,
115145
updateContainer: PropTypes.func,
116146
};
117147

118-
export default connectToContainer(TraceSelector);
148+
export default connectToContainer(localize(TraceSelector));

src/components/widgets/Dropdown.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
22
import React, {Component} from 'react';
33
import Select from 'react-select';
44
import classnames from 'classnames';
5+
import {localize} from 'lib';
56

67
class Dropdown extends Component {
78
constructor(props) {
@@ -40,6 +41,7 @@ class Dropdown extends Component {
4041
disabled,
4142
className,
4243
width,
44+
localize: _,
4345
} = this.props;
4446

4547
const dropdownStyle = {minWidth};
@@ -62,7 +64,7 @@ class Dropdown extends Component {
6264
<div className={dropdownContainerClass} style={dropdownStyle}>
6365
<Select
6466
backspaceToRemoveMessage={backspaceToRemoveMessage}
65-
placeholder={placeholder}
67+
placeholder={placeholder || _('select an option...')}
6668
clearable={clearable}
6769
value={value}
6870
options={opts}
@@ -71,7 +73,7 @@ class Dropdown extends Component {
7173
multi={multi}
7274
optionRenderer={optionRenderer}
7375
valueRenderer={valueRenderer}
74-
noResultsText={noResultsText}
76+
noResultsText={noResultsText || _('no results...')}
7577
valueKey={valueKey}
7678
disabled={disabled}
7779
className={className}
@@ -84,8 +86,6 @@ class Dropdown extends Component {
8486
Dropdown.defaultProps = {
8587
clearable: true,
8688
multi: false,
87-
noResultsText: 'no results...',
88-
placeholder: 'select an option...',
8989
searchable: false,
9090
minWidth: '120px',
9191
valueKey: 'value',
@@ -110,6 +110,7 @@ Dropdown.propTypes = {
110110
disabled: PropTypes.bool,
111111
className: PropTypes.string,
112112
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
113+
localize: PropTypes.func,
113114
};
114115

115-
export default Dropdown;
116+
export default localize(Dropdown);

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
connectTraceToPlot,
88
dereference,
99
localize,
10+
localizeString,
1011
walkObject,
1112
} from './lib';
1213
import {EDITOR_ACTIONS} from './lib/constants';
@@ -85,6 +86,7 @@ export {
8586
connectTraceToPlot,
8687
dereference,
8788
localize,
89+
localizeString,
8890
walkObject,
8991
LayoutPanel,
9092
AxesFold,

src/lib/connectAxesToLayout.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, {Component} from 'react';
22
import PropTypes from 'prop-types';
33
import nestedProperty from 'plotly.js/src/lib/nested_property';
44
import {MULTI_VALUED} from './constants';
5-
import {getDisplayName, isPlainObject} from '../lib';
5+
import {getDisplayName, isPlainObject, localize} from '../lib';
66

77
/**
88
* Simple replacer to use with JSON.stringify.
@@ -92,8 +92,8 @@ function setMultiValuedContainer(intoObj, fromObj, key, config = {}) {
9292
}
9393
}
9494

95-
function computeAxesOptions(axes) {
96-
const options = [{label: 'All', value: 'allaxes'}];
95+
function computeAxesOptions(axes, _) {
96+
const options = [{label: _('All'), value: 'allaxes'}];
9797
for (let i = 0; i < axes.length; i++) {
9898
const ax = axes[i];
9999
const axesPrefix = ax._id.length > 1 ? ' ' + ax._id.substr(1) : '';
@@ -133,7 +133,7 @@ export default function connectAxesToLayout(WrappedComponent) {
133133
} else {
134134
this.axes = [];
135135
}
136-
this.axesOptions = computeAxesOptions(this.axes);
136+
this.axesOptions = computeAxesOptions(this.axes, nextProps.localize);
137137

138138
if (axesTarget === 'allaxes') {
139139
const multiValuedContainer = deepCopyPublic(this.axes[0]);
@@ -210,6 +210,7 @@ export default function connectAxesToLayout(WrappedComponent) {
210210

211211
AxesConnectedComponent.propTypes = {
212212
defaultAxesTarget: PropTypes.string,
213+
localize: PropTypes.func,
213214
};
214215

215216
AxesConnectedComponent.defaultProps = {
@@ -234,5 +235,5 @@ export default function connectAxesToLayout(WrappedComponent) {
234235
updateContainer: PropTypes.func,
235236
};
236237

237-
return AxesConnectedComponent;
238+
return localize(AxesConnectedComponent);
238239
}

0 commit comments

Comments
 (0)