Skip to content

Commit b22dc17

Browse files
committed
refact(i18n): change built output
1 parent 4b61d0d commit b22dc17

17 files changed

+1016
-643
lines changed

.eslintignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/dist
22
/node_modules
33
/build
4-
/src/i18n
4+
/i18n
55
/extension-esm
66
/extension
77
/lib

build/build-i18n.js

+37-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
const fs = require('fs');
2+
const preamble = require('./preamble');
3+
const ts = require('typescript');
4+
const path = require('path');
25

3-
const outFilePath = './i18n';
46
const umdWrapperHead = `
7+
${preamble.js}
8+
/**
9+
* AUTO-GENERATED FILE. DO NOT MODIFY.
10+
*/
511
(function(root, factory) {
612
if (typeof define === 'function' && define.amd) {
713
// AMD. Register as an anonymous module.
@@ -17,9 +23,13 @@ const umdWrapperHead = `
1723
factory({});
1824
}
1925
})(this, function(exports) {
20-
var lang =`;
26+
`;
2127

2228
const umdWrapperHeadWithEcharts = `
29+
${preamble.js}
30+
/**
31+
* AUTO-GENERATED FILE. DO NOT MODIFY.
32+
*/
2333
(function(root, factory) {
2434
if (typeof define === 'function' && define.amd) {
2535
// AMD. Register as an anonymous module.
@@ -35,28 +45,41 @@ const umdWrapperHeadWithEcharts = `
3545
factory({}, root.echarts);
3646
}
3747
})(this, function(exports, echarts) {
38-
var lang =`;
48+
`;
3949

4050
const umdWrapperTail = `
4151
});`;
4252

4353
async function buildI18nWrap() {
44-
const targetDir = './src/i18n';
45-
const files = fs.readdirSync(targetDir);
54+
const targetDir = path.join(__dirname, '../i18n');
55+
const sourceDir = path.join(__dirname, '../src/i18n');
56+
const files = fs.readdirSync(sourceDir);
4657
files.forEach(t => {
47-
if(!t.startsWith('lang') || !t.endsWith('json')) return;
48-
const fileName = t.substring(0, t.length - 5);
49-
const type = t.substr(-7, 2);
58+
if(!t.startsWith('lang')) {
59+
return;
60+
}
61+
const fileName = t.replace(/\.ts$/, '');
62+
const type = fileName.replace(/^lang/, '');
5063
const echartsRegister = `
51-
echarts.registerLocale('${type}', lang);
64+
echarts.registerLocale('${type}', localeObj);
5265
`;
5366
const pureExports = `
54-
exports.lang = lang;
67+
for (var key in localeObj) {
68+
if (localeObj.hasOwnProperty(key)) {
69+
exports[key] = localeObj[key];
70+
}
71+
}
5572
`;
56-
const code = fs.readFileSync(targetDir + '/' + t, 'utf-8');
57-
fs.writeFileSync(outFilePath + '/' + fileName + '.js', umdWrapperHeadWithEcharts + code + echartsRegister + umdWrapperTail, 'utf-8');
58-
fs.writeFileSync(outFilePath + '/' + fileName + '-obj.js', umdWrapperHead + code + pureExports + umdWrapperTail, 'utf-8');
59-
fs.writeFileSync(targetDir + '/' + fileName + '.ts', 'export default ' + code, 'utf-8');
73+
const code = fs.readFileSync(path.join(sourceDir, t), 'utf-8');
74+
// const outputText = ts.transpileModule(code, {
75+
// module: ts.ModuleKind.CommonJS,
76+
// }).outputText;
77+
// Simple regexp replace is enough
78+
const outputCode = code.replace(/export\s+?default/, 'var localeObj =')
79+
.replace(/\/\*([\w\W]*?)\*\//, '');
80+
81+
fs.writeFileSync(path.join(targetDir, fileName + '.js'), umdWrapperHeadWithEcharts + outputCode + echartsRegister + umdWrapperTail, 'utf-8');
82+
fs.writeFileSync(path.join(targetDir, fileName + '-obj.js'), umdWrapperHead + outputCode + pureExports + umdWrapperTail, 'utf-8');
6083
})
6184
console.log('i18n build completed');
6285
}

i18n/langEN-obj.js

+132-89
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11

2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
23+
/**
24+
* AUTO-GENERATED FILE. DO NOT MODIFY.
25+
*/
226
(function(root, factory) {
327
if (typeof define === 'function' && define.amd) {
428
// AMD. Register as an anonymous module.
@@ -14,116 +38,135 @@
1438
factory({});
1539
}
1640
})(this, function(exports) {
17-
var lang ={
18-
"legend": {
19-
"selector": {
20-
"all": "All",
21-
"inverse": "Inv"
41+
42+
43+
/**
44+
* Language: English.
45+
*/
46+
47+
var localeObj = {
48+
time: {
49+
month: [
50+
'January', 'February', 'March', 'April', 'May', 'June',
51+
'July', 'August', 'September', 'October', 'November', 'December'
52+
],
53+
monthAbbr: [
54+
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
55+
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
56+
],
57+
dayOfWeek: [
58+
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
59+
],
60+
dayOfWeekAbbr: [
61+
'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
62+
]
63+
},
64+
legend: {
65+
selector: {
66+
all: 'All',
67+
inverse: 'Inv'
2268
}
2369
},
24-
"toolbox": {
25-
"brush": {
26-
"title": {
27-
"rect": "Box Select",
28-
"polygon": "Lasso Select",
29-
"lineX": "Horizontally Select",
30-
"lineY": "Vertically Select",
31-
"keep": "Keep Selections",
32-
"clear": "Clear Selections"
70+
toolbox: {
71+
brush: {
72+
title: {
73+
rect: 'Box Select',
74+
polygon: 'Lasso Select',
75+
lineX: 'Horizontally Select',
76+
lineY: 'Vertically Select',
77+
keep: 'Keep Selections',
78+
clear: 'Clear Selections'
3379
}
3480
},
35-
"dataView": {
36-
"title": "Data View",
37-
"lang": [
38-
"Data View",
39-
"Close",
40-
"Refresh"
41-
]
81+
dataView: {
82+
title: 'Data View',
83+
lang: ['Data View', 'Close', 'Refresh']
4284
},
43-
"dataZoom": {
44-
"title": {
45-
"zoom": "Zoom",
46-
"back": "Zoom Reset"
85+
dataZoom: {
86+
title: {
87+
zoom: 'Zoom',
88+
back: 'Zoom Reset'
4789
}
4890
},
49-
"magicType": {
50-
"title": {
51-
"line": "Switch to Line Chart",
52-
"bar": "Switch to Bar Chart",
53-
"stack": "Stack",
54-
"tiled": "Tile"
91+
magicType: {
92+
title: {
93+
line: 'Switch to Line Chart',
94+
bar: 'Switch to Bar Chart',
95+
stack: 'Stack',
96+
tiled: 'Tile'
5597
}
5698
},
57-
"restore": {
58-
"title": "Restore"
99+
restore: {
100+
title: 'Restore'
59101
},
60-
"saveAsImage": {
61-
"title": "Save as Image",
62-
"lang": [
63-
"Right Click to Save Image"
64-
]
102+
saveAsImage: {
103+
title: 'Save as Image',
104+
lang: ['Right Click to Save Image']
65105
}
66106
},
67-
"series": {
68-
"typeNames": {
69-
"pie": "Pie chart",
70-
"bar": "Bar chart",
71-
"line": "Line chart",
72-
"scatter": "Scatter plot",
73-
"effectScatter": "Ripple scatter plot",
74-
"radar": "Radar chart",
75-
"tree": "Tree",
76-
"treemap": "Treemap",
77-
"boxplot": "Boxplot",
78-
"candlestick": "Candlestick",
79-
"k": "K line chart",
80-
"heatmap": "Heat map",
81-
"map": "Map",
82-
"parallel": "Parallel coordinate map",
83-
"lines": "Line graph",
84-
"graph": "Relationship graph",
85-
"sankey": "Sankey diagram",
86-
"funnel": "Funnel chart",
87-
"gauge": "Guage",
88-
"pictorialBar": "Pictorial bar",
89-
"themeRiver": "Theme River Map",
90-
"sunburst": "Sunburst"
107+
series: {
108+
typeNames: {
109+
pie: 'Pie chart',
110+
bar: 'Bar chart',
111+
line: 'Line chart',
112+
scatter: 'Scatter plot',
113+
effectScatter: 'Ripple scatter plot',
114+
radar: 'Radar chart',
115+
tree: 'Tree',
116+
treemap: 'Treemap',
117+
boxplot: 'Boxplot',
118+
candlestick: 'Candlestick',
119+
k: 'K line chart',
120+
heatmap: 'Heat map',
121+
map: 'Map',
122+
parallel: 'Parallel coordinate map',
123+
lines: 'Line graph',
124+
graph: 'Relationship graph',
125+
sankey: 'Sankey diagram',
126+
funnel: 'Funnel chart',
127+
gauge: 'Guage',
128+
pictorialBar: 'Pictorial bar',
129+
themeRiver: 'Theme River Map',
130+
sunburst: 'Sunburst'
91131
}
92132
},
93-
"aria": {
94-
"general": {
95-
"withTitle": "This is a chart about \"{title}\"",
96-
"withoutTitle": "This is a chart"
133+
aria: {
134+
general: {
135+
withTitle: 'This is a chart about "{title}"',
136+
withoutTitle: 'This is a chart'
97137
},
98-
"series": {
99-
"single": {
100-
"prefix": "",
101-
"withName": " with type {seriesType} named {seriesName}.",
102-
"withoutName": " with type {seriesType}."
138+
series: {
139+
single: {
140+
prefix: '',
141+
withName: ' with type {seriesType} named {seriesName}.',
142+
withoutName: ' with type {seriesType}.'
103143
},
104-
"multiple": {
105-
"prefix": ". It consists of {seriesCount} series count.",
106-
"withName": " The {seriesId} series is a {seriesType} representing {seriesName}.",
107-
"withoutName": " The {seriesId} series is a {seriesType}.",
108-
"separator": {
109-
"middle": "",
110-
"end": ""
144+
multiple: {
145+
prefix: '. It consists of {seriesCount} series count.',
146+
withName: ' The {seriesId} series is a {seriesType} representing {seriesName}.',
147+
withoutName: ' The {seriesId} series is a {seriesType}.',
148+
separator: {
149+
middle: '',
150+
end: ''
111151
}
112152
}
113153
},
114-
"data": {
115-
"allData": "The data is as follows: ",
116-
"partialData": "The first {displayCnt} items are: ",
117-
"withName": "the data for {name} is {value}",
118-
"withoutName": "{value}",
119-
"separator": {
120-
"middle": ",",
121-
"end": "."
154+
data: {
155+
allData: 'The data is as follows: ',
156+
partialData: 'The first {displayCnt} items are: ',
157+
withName: 'the data for {name} is {value}',
158+
withoutName: '{value}',
159+
separator: {
160+
middle: ', ',
161+
end: '. '
122162
}
123163
}
124164
}
125-
}
126-
127-
exports.lang = lang;
165+
};
166+
for (var key in localeObj) {
167+
if (localeObj.hasOwnProperty(key)) {
168+
exports[key] = localeObj[key];
169+
}
170+
}
128171

129172
});

0 commit comments

Comments
 (0)