Skip to content

Localization #2195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7e075f5
localization routine and tests
alexcjohnson Dec 6, 2017
9a9de77
remove zsmooth that doesn't apply to contourcarpet
alexcjohnson Dec 6, 2017
d859de5
wrap all displayed strings in localize
alexcjohnson Dec 6, 2017
7d057e5
task to collect translation keys and verify syntax
alexcjohnson Dec 6, 2017
8a5eeec
looser placeholder check in titles
alexcjohnson Dec 7, 2017
03dcb5d
lint
alexcjohnson Dec 7, 2017
bf2c6db
move colons into the translations
alexcjohnson Dec 7, 2017
04ed6f0
set default locale to en-US and build this into the library
alexcjohnson Dec 8, 2017
0f8520e
turn log level 1 on by default and move zsmooth messages to logs
alexcjohnson Dec 8, 2017
5d6f267
take <br> out of notifier messages
alexcjohnson Dec 8, 2017
97c0898
include file & line number with translation keys
alexcjohnson Dec 8, 2017
daf0884
disable logging in image server
alexcjohnson Dec 8, 2017
4b48038
convert locales to json, only en(US)? in bundles, and build all local…
alexcjohnson Dec 8, 2017
4b8f980
move geo missing id warn -> log
alexcjohnson Dec 8, 2017
1275661
convert locales back into js instead of json
alexcjohnson Dec 8, 2017
fc03cce
change "unable to bind..." warning to a log
alexcjohnson Dec 8, 2017
cb2f00c
fix command test for warn -> log
alexcjohnson Dec 8, 2017
97821e9
tweak a few of the string literals for consistency
alexcjohnson Dec 8, 2017
e80ec91
fix sankey test and clean log messages from other tests
alexcjohnson Dec 8, 2017
8b9e7d8
remove invalid data from geo_choropleth-text.json
alexcjohnson Dec 8, 2017
6029f94
update finance test for lowercase labels
alexcjohnson Dec 8, 2017
9708b56
update select_test for choropleth mock change
alexcjohnson Dec 9, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/components/colorbar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ module.exports = overrideAll({
title: {
valType: 'string',
role: 'info',
dflt: 'Click to enter colorscale title',
description: 'Sets the title of the color bar.'
},
titlefont: fontAttrs({
Expand Down
2 changes: 1 addition & 1 deletion src/components/colorbar/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = function colorbarDefaults(containerIn, containerOut, layout) {
handleTickMarkDefaults(colorbarIn, colorbarOut, coerce, 'linear',
{outerTicks: false, font: layout.font, noHover: true});

coerce('title');
coerce('title', layout._dfltTitle.colorbar);
Lib.coerceFont(coerce, 'titlefont', layout.font);
coerce('titleside');
};
2 changes: 1 addition & 1 deletion src/components/colorbar/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ module.exports = function draw(gd, id) {
propContainer: cbAxisOut,
propName: propName,
traceIndex: trace.index,
dfltName: 'colorscale',
placeholder: fullLayout._dfltTitle.colorbar,
containerGroup: container.select('.cbtitle')
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/legend/handle_click.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module.exports = function handleClick(g, gd, numClicks) {
}

if(numClicks === 1 && SHOWISOLATETIP && gd.data && gd._context.showTips) {
Lib.notifier('Double click on legend to isolate individual trace', 'long');
Lib.notifier(Lib._(gd, 'Double click on legend to isolate individual trace'), 'long');
SHOWISOLATETIP = false;
} else {
SHOWISOLATETIP = false;
Expand Down
68 changes: 35 additions & 33 deletions src/components/modebar/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var downloadImage = require('../../snapshot/download');
var Icons = require('../../../build/ploticon');


var _ = Lib._;

var modeBarButtons = module.exports = {};

/**
Expand Down Expand Up @@ -47,31 +49,31 @@ var modeBarButtons = module.exports = {};

modeBarButtons.toImage = {
name: 'toImage',
title: 'Download plot as a png',
title: function(gd) { return _(gd, 'Download plot as a png'); },
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of annoying to have to turn all these button titles into functions... just to follow the rule that you can only translate a literal string. In principle we could do this translation in ModeBar.createButton by adding some complexity to the find_locale_strings task to allow one non-literal translation and look for keys inside modebarButtons.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that way you have here is cleaner than more special logic to find_locale_strings 👌

icon: Icons.camera,
click: function(gd) {
var format = 'png';

Lib.notifier('Taking snapshot - this may take a few seconds', 'long');
Lib.notifier(_(gd, 'Taking snapshot - this may take a few seconds'), 'long');

if(Lib.isIE()) {
Lib.notifier('IE only supports svg. Changing format to svg.', 'long');
Lib.notifier(_(gd, 'IE only supports svg. Changing format to svg.'), 'long');
format = 'svg';
}

downloadImage(gd, {'format': format})
.then(function(filename) {
Lib.notifier('Snapshot succeeded - ' + filename, 'long');
Lib.notifier(_(gd, 'Snapshot succeeded') + ' - ' + filename, 'long');
})
.catch(function() {
Lib.notifier('Sorry there was a problem downloading your snapshot!', 'long');
Lib.notifier(_(gd, 'Sorry there was a problem downloading your snapshot!'), 'long');
});
}
};

modeBarButtons.sendDataToCloud = {
name: 'sendDataToCloud',
title: 'Edit in Chart Studio',
title: function(gd) { return _(gd, 'Edit in Chart Studio'); },
icon: Icons.disk,
click: function(gd) {
Plots.sendDataToCloud(gd);
Expand All @@ -80,7 +82,7 @@ modeBarButtons.sendDataToCloud = {

modeBarButtons.zoom2d = {
name: 'zoom2d',
title: 'Zoom',
title: function(gd) { return _(gd, 'Zoom'); },
attr: 'dragmode',
val: 'zoom',
icon: Icons.zoombox,
Expand All @@ -89,7 +91,7 @@ modeBarButtons.zoom2d = {

modeBarButtons.pan2d = {
name: 'pan2d',
title: 'Pan',
title: function(gd) { return _(gd, 'Pan'); },
attr: 'dragmode',
val: 'pan',
icon: Icons.pan,
Expand All @@ -98,7 +100,7 @@ modeBarButtons.pan2d = {

modeBarButtons.select2d = {
name: 'select2d',
title: 'Box Select',
title: function(gd) { return _(gd, 'Box Select'); },
attr: 'dragmode',
val: 'select',
icon: Icons.selectbox,
Expand All @@ -107,7 +109,7 @@ modeBarButtons.select2d = {

modeBarButtons.lasso2d = {
name: 'lasso2d',
title: 'Lasso Select',
title: function(gd) { return _(gd, 'Lasso Select'); },
attr: 'dragmode',
val: 'lasso',
icon: Icons.lasso,
Expand All @@ -116,7 +118,7 @@ modeBarButtons.lasso2d = {

modeBarButtons.zoomIn2d = {
name: 'zoomIn2d',
title: 'Zoom in',
title: function(gd) { return _(gd, 'Zoom in'); },
attr: 'zoom',
val: 'in',
icon: Icons.zoom_plus,
Expand All @@ -125,7 +127,7 @@ modeBarButtons.zoomIn2d = {

modeBarButtons.zoomOut2d = {
name: 'zoomOut2d',
title: 'Zoom out',
title: function(gd) { return _(gd, 'Zoom out'); },
attr: 'zoom',
val: 'out',
icon: Icons.zoom_minus,
Expand All @@ -134,7 +136,7 @@ modeBarButtons.zoomOut2d = {

modeBarButtons.autoScale2d = {
name: 'autoScale2d',
title: 'Autoscale',
title: function(gd) { return _(gd, 'Autoscale'); },
attr: 'zoom',
val: 'auto',
icon: Icons.autoscale,
Expand All @@ -143,7 +145,7 @@ modeBarButtons.autoScale2d = {

modeBarButtons.resetScale2d = {
name: 'resetScale2d',
title: 'Reset axes',
title: function(gd) { return _(gd, 'Reset axes'); },
attr: 'zoom',
val: 'reset',
icon: Icons.home,
Expand All @@ -152,7 +154,7 @@ modeBarButtons.resetScale2d = {

modeBarButtons.hoverClosestCartesian = {
name: 'hoverClosestCartesian',
title: 'Show closest data on hover',
title: function(gd) { return _(gd, 'Show closest data on hover'); },
attr: 'hovermode',
val: 'closest',
icon: Icons.tooltip_basic,
Expand All @@ -162,7 +164,7 @@ modeBarButtons.hoverClosestCartesian = {

modeBarButtons.hoverCompareCartesian = {
name: 'hoverCompareCartesian',
title: 'Compare data on hover',
title: function(gd) { return _(gd, 'Compare data on hover'); },
attr: 'hovermode',
val: function(gd) {
return gd._fullLayout._isHoriz ? 'y' : 'x';
Expand Down Expand Up @@ -256,7 +258,7 @@ function handleCartesian(gd, ev) {

modeBarButtons.zoom3d = {
name: 'zoom3d',
title: 'Zoom',
title: function(gd) { return _(gd, 'Zoom'); },
attr: 'scene.dragmode',
val: 'zoom',
icon: Icons.zoombox,
Expand All @@ -265,7 +267,7 @@ modeBarButtons.zoom3d = {

modeBarButtons.pan3d = {
name: 'pan3d',
title: 'Pan',
title: function(gd) { return _(gd, 'Pan'); },
attr: 'scene.dragmode',
val: 'pan',
icon: Icons.pan,
Expand All @@ -274,7 +276,7 @@ modeBarButtons.pan3d = {

modeBarButtons.orbitRotation = {
name: 'orbitRotation',
title: 'orbital rotation',
title: function(gd) { return _(gd, 'Orbital rotation'); },
attr: 'scene.dragmode',
val: 'orbit',
icon: Icons['3d_rotate'],
Expand All @@ -283,7 +285,7 @@ modeBarButtons.orbitRotation = {

modeBarButtons.tableRotation = {
name: 'tableRotation',
title: 'turntable rotation',
title: function(gd) { return _(gd, 'Turntable rotation'); },
attr: 'scene.dragmode',
val: 'turntable',
icon: Icons['z-axis'],
Expand All @@ -309,15 +311,15 @@ function handleDrag3d(gd, ev) {

modeBarButtons.resetCameraDefault3d = {
name: 'resetCameraDefault3d',
title: 'Reset camera to default',
title: function(gd) { return _(gd, 'Reset camera to default'); },
attr: 'resetDefault',
icon: Icons.home,
click: handleCamera3d
};

modeBarButtons.resetCameraLastSave3d = {
name: 'resetCameraLastSave3d',
title: 'Reset camera to last save',
title: function(gd) { return _(gd, 'Reset camera to last save'); },
attr: 'resetLastSave',
icon: Icons.movie,
click: handleCamera3d
Expand Down Expand Up @@ -348,7 +350,7 @@ function handleCamera3d(gd, ev) {

modeBarButtons.hoverClosest3d = {
name: 'hoverClosest3d',
title: 'Toggle show closest data on hover',
title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },
attr: 'hovermode',
val: null,
toggle: true,
Expand Down Expand Up @@ -409,7 +411,7 @@ function handleHover3d(gd, ev) {

modeBarButtons.zoomInGeo = {
name: 'zoomInGeo',
title: 'Zoom in',
title: function(gd) { return _(gd, 'Zoom in'); },
attr: 'zoom',
val: 'in',
icon: Icons.zoom_plus,
Expand All @@ -418,7 +420,7 @@ modeBarButtons.zoomInGeo = {

modeBarButtons.zoomOutGeo = {
name: 'zoomOutGeo',
title: 'Zoom out',
title: function(gd) { return _(gd, 'Zoom out'); },
attr: 'zoom',
val: 'out',
icon: Icons.zoom_minus,
Expand All @@ -427,7 +429,7 @@ modeBarButtons.zoomOutGeo = {

modeBarButtons.resetGeo = {
name: 'resetGeo',
title: 'Reset',
title: function(gd) { return _(gd, 'Reset'); },
attr: 'reset',
val: null,
icon: Icons.autoscale,
Expand All @@ -436,7 +438,7 @@ modeBarButtons.resetGeo = {

modeBarButtons.hoverClosestGeo = {
name: 'hoverClosestGeo',
title: 'Toggle show closest data on hover',
title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },
attr: 'hovermode',
val: null,
toggle: true,
Expand Down Expand Up @@ -469,7 +471,7 @@ function handleGeo(gd, ev) {

modeBarButtons.hoverClosestGl2d = {
name: 'hoverClosestGl2d',
title: 'Toggle show closest data on hover',
title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },
attr: 'hovermode',
val: null,
toggle: true,
Expand All @@ -480,7 +482,7 @@ modeBarButtons.hoverClosestGl2d = {

modeBarButtons.hoverClosestPie = {
name: 'hoverClosestPie',
title: 'Toggle show closest data on hover',
title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },
attr: 'hovermode',
val: 'closest',
icon: Icons.tooltip_basic,
Expand All @@ -506,7 +508,7 @@ function toggleHover(gd) {

modeBarButtons.toggleHover = {
name: 'toggleHover',
title: 'Toggle show closest data on hover',
title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },
attr: 'hovermode',
val: null,
toggle: true,
Expand All @@ -524,7 +526,7 @@ modeBarButtons.toggleHover = {

modeBarButtons.resetViews = {
name: 'resetViews',
title: 'Reset views',
title: function(gd) { return _(gd, 'Reset views'); },
icon: Icons.home,
click: function(gd, ev) {
var button = ev.currentTarget;
Expand All @@ -543,7 +545,7 @@ modeBarButtons.resetViews = {

modeBarButtons.toggleSpikelines = {
name: 'toggleSpikelines',
title: 'Toggle Spike Lines',
title: function(gd) { return _(gd, 'Toggle Spike Lines'); },
icon: Icons.spikeline,
attr: '_cartesianSpikesEnabled',
val: 'on',
Expand Down Expand Up @@ -578,7 +580,7 @@ function setSpikelineVisibility(gd) {

modeBarButtons.resetViewMapbox = {
name: 'resetViewMapbox',
title: 'Reset view',
title: function(gd) { return _(gd, 'Reset view'); },
attr: 'reset',
icon: Icons.home,
click: function(gd) {
Expand Down
5 changes: 4 additions & 1 deletion src/components/modebar/modebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ proto.createButton = function(config) {

var title = config.title;
if(title === undefined) title = config.name;
// for localization: allow title to be a callable that takes gd as arg
else if(typeof title === 'function') title = title(this.graphInfo);

if(title || title === 0) button.setAttribute('data-title', title);

if(config.attr !== undefined) button.setAttribute('data-attr', config.attr);
Expand Down Expand Up @@ -250,7 +253,7 @@ proto.getLogo = function() {

a.href = 'https://plot.ly/';
a.target = '_blank';
a.setAttribute('data-title', 'Produced with Plotly');
a.setAttribute('data-title', Lib._(this.graphInfo, 'Produced with Plotly'));
a.className = 'modebar-btn plotlyjsicon modebar-btn--logo';

a.appendChild(this.createIcon(Icons.plotlylogo));
Expand Down
3 changes: 2 additions & 1 deletion src/components/rangeslider/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ function drawRangePlot(rangeSlider, gd, axisOpts, opts) {
width: opts._width,
height: opts._height,
margin: { t: 0, b: 0, l: 0, r: 0 }
}
},
_context: gd._context
};

mockFigure.layout[oppAxisName] = {
Expand Down
Loading