Skip to content

Commit 1275661

Browse files
committed
convert locales back into js instead of json
1 parent 4b8f980 commit 1275661

15 files changed

+67
-42
lines changed

lib/index-basic.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Plotly.register([
1717

1818
// locales
1919
Plotly.register([
20-
require('./locale-en.json'),
21-
require('./locale-en-us.json')
20+
require('./locale-en'),
21+
require('./locale-en-us')
2222
]);
2323

2424
module.exports = Plotly;

lib/index-cartesian.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ Plotly.register([
2525

2626
// locales
2727
Plotly.register([
28-
require('./locale-en.json'),
29-
require('./locale-en-us.json')
28+
require('./locale-en'),
29+
require('./locale-en-us')
3030
]);
3131

3232
module.exports = Plotly;

lib/index-finance.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Plotly.register([
2020

2121
// locales
2222
Plotly.register([
23-
require('./locale-en.json'),
24-
require('./locale-en-us.json')
23+
require('./locale-en'),
24+
require('./locale-en-us')
2525
]);
2626

2727
module.exports = Plotly;

lib/index-geo.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Plotly.register([
1717

1818
// locales
1919
Plotly.register([
20-
require('./locale-en.json'),
21-
require('./locale-en-us.json')
20+
require('./locale-en'),
21+
require('./locale-en-us')
2222
]);
2323

2424
module.exports = Plotly;

lib/index-gl2d.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Plotly.register([
2020

2121
// locales
2222
Plotly.register([
23-
require('./locale-en.json'),
24-
require('./locale-en-us.json')
23+
require('./locale-en'),
24+
require('./locale-en-us')
2525
]);
2626

2727
module.exports = Plotly;

lib/index-gl3d.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Plotly.register([
1818

1919
// locales
2020
Plotly.register([
21-
require('./locale-en.json'),
22-
require('./locale-en-us.json')
21+
require('./locale-en'),
22+
require('./locale-en-us')
2323
]);
2424

2525
module.exports = Plotly;

lib/index-mapbox.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Plotly.register([
1616

1717
// locales
1818
Plotly.register([
19-
require('./locale-en.json'),
20-
require('./locale-en-us.json')
19+
require('./locale-en'),
20+
require('./locale-en-us')
2121
]);
2222

2323
module.exports = Plotly;

lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ Plotly.register([
7373

7474
// locales
7575
Plotly.register([
76-
require('./locale-en.json'),
77-
require('./locale-en-us.json')
76+
require('./locale-en.js'),
77+
require('./locale-en-us.js')
7878
]);
7979

8080
module.exports = Plotly;

lib/locale-en-us.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = {
12+
moduleType: 'locale',
13+
name: 'en-US',
14+
dictionary: {
15+
'Click to enter Colorscale title': 'Click to enter Colorscale title'
16+
}
17+
};

lib/locale-en-us.json

-7
This file was deleted.

lib/locale-en.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = {
12+
moduleType: 'locale',
13+
name: 'en',
14+
dictionary: {
15+
'Click to enter Colorscale title': 'Click to enter Colourscale title'
16+
}
17+
};

lib/locale-en.json

-7
This file was deleted.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
"world-calendars": "^1.0.3"
109109
},
110110
"devDependencies": {
111-
"add-stream": "^1.0.0",
112111
"brfs": "^1.4.3",
113112
"browserify": "^14.1.0",
114113
"browserify-transform-tools": "^1.7.0",

tasks/bundle.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ constants.partialBundlePaths.forEach(function(pathObj) {
6060
});
6161

6262
// "Browserify" the locales
63-
var localeGlob = path.join(constants.pathToLib, 'locale-*.json');
63+
var localeGlob = path.join(constants.pathToLib, 'locale-*.js');
6464
glob(localeGlob, function(err, files) {
6565
files.forEach(function(file) {
66-
var outName = 'plotly-' + path.basename(file).replace(/.json$/, '.js');
66+
var outName = 'plotly-' + path.basename(file);
6767
var outPath = path.join(constants.pathToDist, outName);
6868
wrapLocale(file, outPath);
6969
});

tasks/util/wrap_locale.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ var path = require('path');
33

44
var minify = require('minify-stream');
55
var intoStream = require('into-stream');
6-
var addStream = require('add-stream');
76

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

109
var prefix = 'Plotly.register(';
1110
var suffix = ');';
1211

12+
var moduleMarker = 'module.exports = ';
13+
1314
/** Wrap a locale json file into a standalone js file
1415
*
1516
* @param {string} pathToInput path to the locale json file
@@ -18,14 +19,19 @@ var suffix = ');';
1819
* Logs basename of bundle when completed.
1920
*/
2021
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-
});
22+
fs.readFile(pathToInput, 'utf8', function(err, data) {
23+
var moduleStart = data.indexOf(moduleMarker) + moduleMarker.length;
24+
var moduleEnd = data.indexOf(';', moduleStart);
25+
26+
var rawOut = prefix + data.substr(moduleStart, moduleEnd - moduleStart) + suffix;
27+
28+
intoStream(rawOut)
29+
.pipe(minify(constants.uglifyOptions))
30+
.pipe(fs.createWriteStream(pathToOutput))
31+
.on('finish', function() {
32+
logger(pathToOutput);
33+
});
34+
});
2935
};
3036

3137
function logger(pathToOutput) {

0 commit comments

Comments
 (0)