Skip to content

Commit 4b48038

Browse files
committed
convert locales to json, only en(US)? in bundles, and build all locales for dist
1 parent daf0884 commit 4b48038

18 files changed

+99
-56
lines changed

dist/plotly-locale-en-us.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/plotly-locale-en.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index-basic.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Plotly.register([
1616
]);
1717

1818
// locales
19-
Plotly.register(require('./locales.js'));
19+
Plotly.register([
20+
require('./locale-en.json'),
21+
require('./locale-en-us.json')
22+
]);
2023

2124
module.exports = Plotly;

lib/index-cartesian.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Plotly.register([
2424
]);
2525

2626
// locales
27-
Plotly.register(require('./locales.js'));
27+
Plotly.register([
28+
require('./locale-en.json'),
29+
require('./locale-en-us.json')
30+
]);
2831

2932
module.exports = Plotly;

lib/index-finance.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Plotly.register([
1919
]);
2020

2121
// locales
22-
Plotly.register(require('./locales.js'));
22+
Plotly.register([
23+
require('./locale-en.json'),
24+
require('./locale-en-us.json')
25+
]);
2326

2427
module.exports = Plotly;

lib/index-geo.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Plotly.register([
1616
]);
1717

1818
// locales
19-
Plotly.register(require('./locales.js'));
19+
Plotly.register([
20+
require('./locale-en.json'),
21+
require('./locale-en-us.json')
22+
]);
2023

2124
module.exports = Plotly;

lib/index-gl2d.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Plotly.register([
1919
]);
2020

2121
// locales
22-
Plotly.register(require('./locales.js'));
22+
Plotly.register([
23+
require('./locale-en.json'),
24+
require('./locale-en-us.json')
25+
]);
2326

2427
module.exports = Plotly;

lib/index-gl3d.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Plotly.register([
1717
]);
1818

1919
// locales
20-
Plotly.register(require('./locales.js'));
20+
Plotly.register([
21+
require('./locale-en.json'),
22+
require('./locale-en-us.json')
23+
]);
2124

2225
module.exports = Plotly;

lib/index-mapbox.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Plotly.register([
1515
]);
1616

1717
// locales
18-
Plotly.register(require('./locales.js'));
18+
Plotly.register([
19+
require('./locale-en.json'),
20+
require('./locale-en-us.json')
21+
]);
1922

2023
module.exports = Plotly;

lib/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ Plotly.register([
7272
]);
7373

7474
// locales
75-
Plotly.register(require('./locales.js'));
75+
Plotly.register([
76+
require('./locale-en.json'),
77+
require('./locale-en-us.json')
78+
]);
7679

7780
module.exports = Plotly;

lib/locale-en-us.js

-17
This file was deleted.

lib/locale-en-us.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"moduleType": "locale",
3+
"name": "en-US",
4+
"dictionary": {
5+
"Click to enter Colorscale title": "Click to enter Colorscale title"
6+
}
7+
}

lib/locale-en.js

-17
This file was deleted.

lib/locale-en.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"moduleType": "locale",
3+
"name": "en",
4+
"dictionary": {
5+
"Click to enter Colorscale title": "Click to enter Colourscale title"
6+
}
7+
}

lib/locales.js

-14
This file was deleted.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"world-calendars": "^1.0.3"
109109
},
110110
"devDependencies": {
111+
"add-stream": "^1.0.0",
111112
"brfs": "^1.4.3",
112113
"browserify": "^14.1.0",
113114
"browserify-transform-tools": "^1.7.0",
@@ -122,6 +123,7 @@
122123
"glslify": "^4.0.0",
123124
"gzip-size": "^3.0.0",
124125
"image-size": "^0.5.1",
126+
"into-stream": "^3.1.0",
125127
"jasmine-core": "^2.4.1",
126128
"jsdom": "^11.2.0",
127129
"karma": "^1.5.0",

tasks/bundle.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
var path = require('path');
2+
var glob = require('glob');
3+
14
var constants = require('./util/constants');
25
var common = require('./util/common');
36
var _bundle = require('./util/browserify_wrapper');
47
var makeSchema = require('./util/make_schema');
8+
var wrapLocale = require('./util/wrap_locale');
59
/*
610
* This script takes one argument
711
*
@@ -54,3 +58,13 @@ constants.partialBundlePaths.forEach(function(pathObj) {
5458
pathToMinBundle: pathObj.distMin
5559
});
5660
});
61+
62+
// "Browserify" the locales
63+
var localeGlob = path.join(constants.pathToLib, 'locale-*.json');
64+
glob(localeGlob, function(err, files) {
65+
files.forEach(function(file) {
66+
var outName = 'plotly-' + path.basename(file).replace(/.json$/, '.js');
67+
var outPath = path.join(constants.pathToDist, outName);
68+
wrapLocale(file, outPath);
69+
});
70+
});

tasks/util/wrap_locale.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var fs = require('fs');
2+
var path = require('path');
3+
4+
var minify = require('minify-stream');
5+
var intoStream = require('into-stream');
6+
var addStream = require('add-stream');
7+
8+
var constants = require('./constants');
9+
10+
var prefix = 'Plotly.register(';
11+
var suffix = ');';
12+
13+
/** Wrap a locale json file into a standalone js file
14+
*
15+
* @param {string} pathToInput path to the locale json file
16+
* @param {string} pathToOutput path to destination file
17+
*
18+
* Logs basename of bundle when completed.
19+
*/
20+
module.exports = function wrap_locale(pathToInput, pathToOutput) {
21+
intoStream(prefix)
22+
.pipe(addStream(fs.createReadStream(pathToInput)))
23+
.pipe(addStream(intoStream(suffix)))
24+
.pipe(minify(constants.uglifyOptions))
25+
.pipe(fs.createWriteStream(pathToOutput))
26+
.on('finish', function() {
27+
logger(pathToOutput);
28+
});
29+
};
30+
31+
function logger(pathToOutput) {
32+
var log = 'ok ' + path.basename(pathToOutput);
33+
34+
console.log(log);
35+
}

0 commit comments

Comments
 (0)