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: 1 addition & 0 deletions dist/plotly-locale-en-us.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/plotly-locale-en.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/index-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Plotly.register([
]);

// locales
Plotly.register(require('./locales.js'));
Plotly.register([
require('./locale-en.json'),
require('./locale-en-us.json')
Copy link
Contributor

Choose a reason for hiding this comment

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

Ha. Webpack users won't like that. Webpack (v1 at least) needs a special loader to bundle JSON files unlike browserify. See #183

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, back to js 1275661

]);

module.exports = Plotly;
5 changes: 4 additions & 1 deletion lib/index-cartesian.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Plotly.register([
]);

// locales
Plotly.register(require('./locales.js'));
Plotly.register([
require('./locale-en.json'),
require('./locale-en-us.json')
]);

module.exports = Plotly;
5 changes: 4 additions & 1 deletion lib/index-finance.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Plotly.register([
]);

// locales
Plotly.register(require('./locales.js'));
Plotly.register([
require('./locale-en.json'),
require('./locale-en-us.json')
]);

module.exports = Plotly;
5 changes: 4 additions & 1 deletion lib/index-geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Plotly.register([
]);

// locales
Plotly.register(require('./locales.js'));
Plotly.register([
require('./locale-en.json'),
require('./locale-en-us.json')
]);

module.exports = Plotly;
5 changes: 4 additions & 1 deletion lib/index-gl2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Plotly.register([
]);

// locales
Plotly.register(require('./locales.js'));
Plotly.register([
require('./locale-en.json'),
require('./locale-en-us.json')
]);

module.exports = Plotly;
5 changes: 4 additions & 1 deletion lib/index-gl3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Plotly.register([
]);

// locales
Plotly.register(require('./locales.js'));
Plotly.register([
require('./locale-en.json'),
require('./locale-en-us.json')
]);

module.exports = Plotly;
5 changes: 4 additions & 1 deletion lib/index-mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Plotly.register([
]);

// locales
Plotly.register(require('./locales.js'));
Plotly.register([
require('./locale-en.json'),
require('./locale-en-us.json')
]);

module.exports = Plotly;
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ Plotly.register([
]);

// locales
Plotly.register(require('./locales.js'));
Plotly.register([
require('./locale-en.json'),
require('./locale-en-us.json')
]);

module.exports = Plotly;
17 changes: 0 additions & 17 deletions lib/locale-en-us.js

This file was deleted.

7 changes: 7 additions & 0 deletions lib/locale-en-us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"moduleType": "locale",
"name": "en-US",
"dictionary": {
"Click to enter Colorscale title": "Click to enter Colorscale title"
}
}
17 changes: 0 additions & 17 deletions lib/locale-en.js

This file was deleted.

7 changes: 7 additions & 0 deletions lib/locale-en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"moduleType": "locale",
"name": "en",
"dictionary": {
"Click to enter Colorscale title": "Click to enter Colourscale title"
}
}
14 changes: 0 additions & 14 deletions lib/locales.js

This file was deleted.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"world-calendars": "^1.0.3"
},
"devDependencies": {
"add-stream": "^1.0.0",
"brfs": "^1.4.3",
"browserify": "^14.1.0",
"browserify-transform-tools": "^1.7.0",
Expand All @@ -122,6 +123,7 @@
"glslify": "^4.0.0",
"gzip-size": "^3.0.0",
"image-size": "^0.5.1",
"into-stream": "^3.1.0",
"jasmine-core": "^2.4.1",
"jsdom": "^11.2.0",
"karma": "^1.5.0",
Expand Down
14 changes: 14 additions & 0 deletions tasks/bundle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
var path = require('path');
var glob = require('glob');

var constants = require('./util/constants');
var common = require('./util/common');
var _bundle = require('./util/browserify_wrapper');
var makeSchema = require('./util/make_schema');
var wrapLocale = require('./util/wrap_locale');
/*
* This script takes one argument
*
Expand Down Expand Up @@ -54,3 +58,13 @@ constants.partialBundlePaths.forEach(function(pathObj) {
pathToMinBundle: pathObj.distMin
});
});

// "Browserify" the locales
var localeGlob = path.join(constants.pathToLib, 'locale-*.json');
glob(localeGlob, function(err, files) {
files.forEach(function(file) {
var outName = 'plotly-' + path.basename(file).replace(/.json$/, '.js');
var outPath = path.join(constants.pathToDist, outName);
wrapLocale(file, outPath);
});
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@etpinard what do you think about this solution?

  • Turned the locales into json files
  • Explicitly loaded just 'en' and 'en-US' into the built bundles (ie I got rid of locales.js so that if/when we add more locales they will not automatically go into all the bundles) but we'll still put new locales into lib/ for use if you make your own bundle.
  • Built separate minified js files for each locale, so if you load via a script tag (from CDN or script) you can first load plotly.js and then in the next script tag load the locale you want.

Copy link
Contributor

Choose a reason for hiding this comment

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

Turned the locales into json files

Requiring JSON files isn't ideal as described in #2195 (comment)

I'd vote for converting those lib/locale-??? files into plain js files.

so that if/when we add more locales they will not automatically go into all the bundles) but we'll still put new locales into lib/ for use if you make your own bundle.

great 👌

Built separate minified js files for each locale, so if you load via a script tag (from CDN or script) you can first load plotly.js and then in the next script tag load the locale you want.

Lovely ❤️ and by the looks of it out push-to-cdn script should just worktm.

35 changes: 35 additions & 0 deletions tasks/util/wrap_locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var fs = require('fs');
var path = require('path');

var minify = require('minify-stream');
var intoStream = require('into-stream');
var addStream = require('add-stream');

var constants = require('./constants');

var prefix = 'Plotly.register(';
var suffix = ');';

/** Wrap a locale json file into a standalone js file
*
* @param {string} pathToInput path to the locale json file
* @param {string} pathToOutput path to destination file
*
* Logs basename of bundle when completed.
*/
module.exports = function wrap_locale(pathToInput, pathToOutput) {
intoStream(prefix)
.pipe(addStream(fs.createReadStream(pathToInput)))
.pipe(addStream(intoStream(suffix)))
.pipe(minify(constants.uglifyOptions))
.pipe(fs.createWriteStream(pathToOutput))
.on('finish', function() {
logger(pathToOutput);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Smooth work with add-stream and info-stream. It would be nice to rewrite the addHeadersInDistFiles step in tasks/header.js using streams for 🐎

};

function logger(pathToOutput) {
var log = 'ok ' + path.basename(pathToOutput);

console.log(log);
}