Skip to content

Commit 7d057e5

Browse files
committed
task to collect translation keys and verify syntax
1 parent d859de5 commit 7d057e5

File tree

4 files changed

+149
-2
lines changed

4 files changed

+149
-2
lines changed

dist/translationKeys.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Autoscale
2+
Box Select
3+
Click to enter Colorscale title
4+
Click to enter Component A title
5+
Click to enter Component B title
6+
Click to enter Component C title
7+
Click to enter Plot title
8+
Click to enter X axis title
9+
Click to enter Y axis title
10+
Close
11+
Compare data on hover
12+
Double click on legend to isolate individual trace
13+
Double-click to<br>zoom back out
14+
Download plot as a png
15+
High
16+
IE only supports svg. Changing format to svg.
17+
Incoming flow count
18+
Lasso Select
19+
Low
20+
Open
21+
Orbital rotation
22+
Outgoing flow count
23+
Pan
24+
Produced with Plotly
25+
Reset
26+
Reset axes
27+
Reset camera to default
28+
Reset camera to last save
29+
Reset view
30+
Reset views
31+
Save and edit plot in cloud
32+
Show closest data on hover
33+
Snapshot succeeded
34+
Sorry there was a problem downloading your snapshot!
35+
Source
36+
Taking snapshot - this may take a few seconds
37+
Target
38+
Toggle Spike Lines
39+
Toggle show closest data on hover
40+
Turntable rotation
41+
Zoom
42+
Zoom in
43+
Zoom out
44+
cannot use zsmooth: "fast"
45+
kde
46+
lat
47+
log axis found
48+
lon
49+
lower fence
50+
max
51+
mean
52+
mean ± σ
53+
median
54+
min
55+
q1
56+
q3
57+
trace
58+
upper fence
59+
x scale is not linear
60+
y scale is not linear

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"bundle": "node tasks/bundle.js",
2626
"header": "node tasks/header.js",
2727
"stats": "node tasks/stats.js",
28-
"build": "npm run preprocess && npm run bundle && npm run header && npm run stats",
28+
"find-strings": "node tasks/find_locale_strings.js",
29+
"build": "npm run preprocess && npm run find-strings && npm run bundle && npm run header && npm run stats",
2930
"cibuild": "npm run preprocess && node tasks/cibundle.js",
3031
"watch": "node tasks/watch.js",
3132
"lint": "eslint --version && eslint .",
@@ -36,7 +37,7 @@
3637
"test-image": "node tasks/test_image.js",
3738
"test-image-gl2d": "node tasks/test_image.js gl2d_* --queue",
3839
"test-export": "node tasks/test_export.js",
39-
"test-syntax": "node tasks/test_syntax.js",
40+
"test-syntax": "node tasks/test_syntax.js && npm run find-strings",
4041
"test-bundle": "node tasks/test_bundle.js",
4142
"test": "npm run test-jasmine && npm run test-bundle && npm run test-image && npm run test-image-gl2d && npm run test-syntax && npm run lint",
4243
"start-test_dashboard": "node devtools/test_dashboard/server.js",

tasks/find_locale_strings.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
var path = require('path');
2+
var fs = require('fs');
3+
4+
var falafel = require('falafel');
5+
var glob = require('glob');
6+
7+
var constants = require('./util/constants');
8+
var srcGlob = path.join(constants.pathToSrc, '**/*.js');
9+
10+
var common = require('./util/common');
11+
12+
var EXIT_CODE = 0;
13+
14+
var localizeRE = /(^|[\.])(_|localize)$/;
15+
16+
// main
17+
findLocaleStrings();
18+
19+
function findLocaleStrings() {
20+
glob(srcGlob, function(err, files) {
21+
if(err) {
22+
EXIT_CODE = 1;
23+
console.log(err);
24+
return;
25+
}
26+
27+
var dict = {};
28+
var hasTranslation = false;
29+
30+
files.forEach(function(file) {
31+
var code = fs.readFileSync(file, 'utf-8');
32+
33+
falafel(code, {locations: true}, function(node) {
34+
// parse through code string looking for translated strings
35+
// You may either assign `Lib.localize` to `_` and use that, or
36+
// call `Lib.localize` directly.
37+
if(node.type === 'CallExpression' &&
38+
(node.callee.name === '_' || node.callee.source() === 'Lib._')
39+
) {
40+
var strNode = node.arguments[1];
41+
if(node.arguments.length !== 2) {
42+
logError(file, node, 'Localize takes 2 args');
43+
}
44+
if(strNode.type !== 'Literal') {
45+
logError(file, node, 'Translated string must be a literal');
46+
}
47+
dict[strNode.value] = 1;
48+
hasTranslation = true;
49+
}
50+
51+
// make sure localize is the only thing we assign to a variable `_`
52+
// NB: this does not preclude using `_` for an unused function arg
53+
else if(node.type === 'VariableDeclarator' && node.id.name === '_') {
54+
var src = node.init.source();
55+
if(!localizeRE.test(src)) {
56+
logError(file, node, 'Use `_` only to mean localization');
57+
}
58+
}
59+
});
60+
});
61+
62+
if(!hasTranslation) {
63+
console.error('Found no translations.');
64+
EXIT_CODE = 1;
65+
}
66+
67+
if(!EXIT_CODE) {
68+
var strings = Object.keys(dict).sort().join('\n');
69+
common.writeFile(constants.pathToTranslationKeys, strings);
70+
console.log('ok find_locale_strings');
71+
}
72+
});
73+
}
74+
75+
function logError(file, node, msg) {
76+
console.error(file + ' [line ' + node.loc.start.line + '] ' + msg +
77+
'\n ' + node.source());
78+
EXIT_CODE = 1;
79+
}
80+
81+
process.on('exit', function() {
82+
if(EXIT_CODE) {
83+
throw new Error('find_locale_strings failed.');
84+
}
85+
});

tasks/util/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module.exports = {
4242
pathToPlotlyDistWithMeta: path.join(pathToDist, 'plotly-with-meta.js'),
4343

4444
pathToSchema: path.join(pathToDist, 'plot-schema.json'),
45+
pathToTranslationKeys: path.join(pathToDist, 'translationKeys.txt'),
4546

4647
partialBundleNames: partialBundleNames,
4748
partialBundlePaths: partialBundlePaths,

0 commit comments

Comments
 (0)