Skip to content

Commit

Permalink
refact(i18n): change built output
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Jul 30, 2020
1 parent 4b61d0d commit b22dc17
Show file tree
Hide file tree
Showing 17 changed files with 1,016 additions and 643 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/dist
/node_modules
/build
/src/i18n
/i18n
/extension-esm
/extension
/lib
Expand Down
51 changes: 37 additions & 14 deletions build/build-i18n.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const fs = require('fs');
const preamble = require('./preamble');
const ts = require('typescript');
const path = require('path');

const outFilePath = './i18n';
const umdWrapperHead = `
${preamble.js}
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
Expand All @@ -17,9 +23,13 @@ const umdWrapperHead = `
factory({});
}
})(this, function(exports) {
var lang =`;
`;

const umdWrapperHeadWithEcharts = `
${preamble.js}
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
Expand All @@ -35,28 +45,41 @@ const umdWrapperHeadWithEcharts = `
factory({}, root.echarts);
}
})(this, function(exports, echarts) {
var lang =`;
`;

const umdWrapperTail = `
});`;

async function buildI18nWrap() {
const targetDir = './src/i18n';
const files = fs.readdirSync(targetDir);
const targetDir = path.join(__dirname, '../i18n');
const sourceDir = path.join(__dirname, '../src/i18n');
const files = fs.readdirSync(sourceDir);
files.forEach(t => {
if(!t.startsWith('lang') || !t.endsWith('json')) return;
const fileName = t.substring(0, t.length - 5);
const type = t.substr(-7, 2);
if(!t.startsWith('lang')) {
return;
}
const fileName = t.replace(/\.ts$/, '');
const type = fileName.replace(/^lang/, '');
const echartsRegister = `
echarts.registerLocale('${type}', lang);
echarts.registerLocale('${type}', localeObj);
`;
const pureExports = `
exports.lang = lang;
for (var key in localeObj) {
if (localeObj.hasOwnProperty(key)) {
exports[key] = localeObj[key];
}
}
`;
const code = fs.readFileSync(targetDir + '/' + t, 'utf-8');
fs.writeFileSync(outFilePath + '/' + fileName + '.js', umdWrapperHeadWithEcharts + code + echartsRegister + umdWrapperTail, 'utf-8');
fs.writeFileSync(outFilePath + '/' + fileName + '-obj.js', umdWrapperHead + code + pureExports + umdWrapperTail, 'utf-8');
fs.writeFileSync(targetDir + '/' + fileName + '.ts', 'export default ' + code, 'utf-8');
const code = fs.readFileSync(path.join(sourceDir, t), 'utf-8');
// const outputText = ts.transpileModule(code, {
// module: ts.ModuleKind.CommonJS,
// }).outputText;
// Simple regexp replace is enough
const outputCode = code.replace(/export\s+?default/, 'var localeObj =')
.replace(/\/\*([\w\W]*?)\*\//, '');

fs.writeFileSync(path.join(targetDir, fileName + '.js'), umdWrapperHeadWithEcharts + outputCode + echartsRegister + umdWrapperTail, 'utf-8');
fs.writeFileSync(path.join(targetDir, fileName + '-obj.js'), umdWrapperHead + outputCode + pureExports + umdWrapperTail, 'utf-8');
})
console.log('i18n build completed');
}
Expand Down
221 changes: 132 additions & 89 deletions i18n/langEN-obj.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@


/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/


/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
Expand All @@ -14,116 +38,135 @@
factory({});
}
})(this, function(exports) {
var lang ={
"legend": {
"selector": {
"all": "All",
"inverse": "Inv"


/**
* Language: English.
*/

var localeObj = {
time: {
month: [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
],
monthAbbr: [
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
],
dayOfWeek: [
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
],
dayOfWeekAbbr: [
'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
]
},
legend: {
selector: {
all: 'All',
inverse: 'Inv'
}
},
"toolbox": {
"brush": {
"title": {
"rect": "Box Select",
"polygon": "Lasso Select",
"lineX": "Horizontally Select",
"lineY": "Vertically Select",
"keep": "Keep Selections",
"clear": "Clear Selections"
toolbox: {
brush: {
title: {
rect: 'Box Select',
polygon: 'Lasso Select',
lineX: 'Horizontally Select',
lineY: 'Vertically Select',
keep: 'Keep Selections',
clear: 'Clear Selections'
}
},
"dataView": {
"title": "Data View",
"lang": [
"Data View",
"Close",
"Refresh"
]
dataView: {
title: 'Data View',
lang: ['Data View', 'Close', 'Refresh']
},
"dataZoom": {
"title": {
"zoom": "Zoom",
"back": "Zoom Reset"
dataZoom: {
title: {
zoom: 'Zoom',
back: 'Zoom Reset'
}
},
"magicType": {
"title": {
"line": "Switch to Line Chart",
"bar": "Switch to Bar Chart",
"stack": "Stack",
"tiled": "Tile"
magicType: {
title: {
line: 'Switch to Line Chart',
bar: 'Switch to Bar Chart',
stack: 'Stack',
tiled: 'Tile'
}
},
"restore": {
"title": "Restore"
restore: {
title: 'Restore'
},
"saveAsImage": {
"title": "Save as Image",
"lang": [
"Right Click to Save Image"
]
saveAsImage: {
title: 'Save as Image',
lang: ['Right Click to Save Image']
}
},
"series": {
"typeNames": {
"pie": "Pie chart",
"bar": "Bar chart",
"line": "Line chart",
"scatter": "Scatter plot",
"effectScatter": "Ripple scatter plot",
"radar": "Radar chart",
"tree": "Tree",
"treemap": "Treemap",
"boxplot": "Boxplot",
"candlestick": "Candlestick",
"k": "K line chart",
"heatmap": "Heat map",
"map": "Map",
"parallel": "Parallel coordinate map",
"lines": "Line graph",
"graph": "Relationship graph",
"sankey": "Sankey diagram",
"funnel": "Funnel chart",
"gauge": "Guage",
"pictorialBar": "Pictorial bar",
"themeRiver": "Theme River Map",
"sunburst": "Sunburst"
series: {
typeNames: {
pie: 'Pie chart',
bar: 'Bar chart',
line: 'Line chart',
scatter: 'Scatter plot',
effectScatter: 'Ripple scatter plot',
radar: 'Radar chart',
tree: 'Tree',
treemap: 'Treemap',
boxplot: 'Boxplot',
candlestick: 'Candlestick',
k: 'K line chart',
heatmap: 'Heat map',
map: 'Map',
parallel: 'Parallel coordinate map',
lines: 'Line graph',
graph: 'Relationship graph',
sankey: 'Sankey diagram',
funnel: 'Funnel chart',
gauge: 'Guage',
pictorialBar: 'Pictorial bar',
themeRiver: 'Theme River Map',
sunburst: 'Sunburst'
}
},
"aria": {
"general": {
"withTitle": "This is a chart about \"{title}\"",
"withoutTitle": "This is a chart"
aria: {
general: {
withTitle: 'This is a chart about "{title}"',
withoutTitle: 'This is a chart'
},
"series": {
"single": {
"prefix": "",
"withName": " with type {seriesType} named {seriesName}.",
"withoutName": " with type {seriesType}."
series: {
single: {
prefix: '',
withName: ' with type {seriesType} named {seriesName}.',
withoutName: ' with type {seriesType}.'
},
"multiple": {
"prefix": ". It consists of {seriesCount} series count.",
"withName": " The {seriesId} series is a {seriesType} representing {seriesName}.",
"withoutName": " The {seriesId} series is a {seriesType}.",
"separator": {
"middle": "",
"end": ""
multiple: {
prefix: '. It consists of {seriesCount} series count.',
withName: ' The {seriesId} series is a {seriesType} representing {seriesName}.',
withoutName: ' The {seriesId} series is a {seriesType}.',
separator: {
middle: '',
end: ''
}
}
},
"data": {
"allData": "The data is as follows: ",
"partialData": "The first {displayCnt} items are: ",
"withName": "the data for {name} is {value}",
"withoutName": "{value}",
"separator": {
"middle": ",",
"end": "."
data: {
allData: 'The data is as follows: ',
partialData: 'The first {displayCnt} items are: ',
withName: 'the data for {name} is {value}',
withoutName: '{value}',
separator: {
middle: ', ',
end: '. '
}
}
}
}

exports.lang = lang;
};
for (var key in localeObj) {
if (localeObj.hasOwnProperty(key)) {
exports[key] = localeObj[key];
}
}

});
Loading

0 comments on commit b22dc17

Please sign in to comment.