From 950275dd5f931cfaedc6b2458192ebe0e29c42b9 Mon Sep 17 00:00:00 2001 From: zakwu <123537200@qq.com> Date: Mon, 27 Jul 2020 16:56:20 +0800 Subject: [PATCH 01/14] feat(i18n): draft commit for discuss --- i18n/langEN.js | 144 +++++++++++++++++++ {src => i18n}/langES.ts | 0 {src => i18n}/langFI.ts | 0 {src => i18n}/langTH.ts | 0 i18n/langZH.js | 141 ++++++++++++++++++ src/component/legend/LegendModel.ts | 34 +++-- src/component/toolbox/ToolboxModel.ts | 7 +- src/component/toolbox/feature/Brush.ts | 41 +++--- src/component/toolbox/feature/DataView.ts | 44 +++--- src/component/toolbox/feature/DataZoom.ts | 28 ++-- src/component/toolbox/feature/MagicType.ts | 44 +++--- src/component/toolbox/feature/Restore.ts | 21 +-- src/component/toolbox/feature/SaveAsImage.ts | 34 ++--- src/component/toolbox/featureManager.ts | 3 +- src/echarts.ts | 19 ++- src/lang.ts | 126 ---------------- src/langEN.ts | 126 ---------------- src/model/Global.ts | 27 +++- src/util/types.ts | 1 + src/visual/aria.ts | 4 +- test/lang.html | 104 ++++++++++++++ 21 files changed, 574 insertions(+), 374 deletions(-) create mode 100644 i18n/langEN.js rename {src => i18n}/langES.ts (100%) rename {src => i18n}/langFI.ts (100%) rename {src => i18n}/langTH.ts (100%) create mode 100644 i18n/langZH.js delete mode 100644 src/lang.ts delete mode 100644 src/langEN.ts create mode 100644 test/lang.html diff --git a/i18n/langEN.js b/i18n/langEN.js new file mode 100644 index 0000000000..ebba3a159b --- /dev/null +++ b/i18n/langEN.js @@ -0,0 +1,144 @@ +/* + * 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. + */ + +/** + * Language: English. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports', 'echarts'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports, require('echarts')); + } else { + // Browser globals + factory({}, root.echarts); + } +})(this, function(exports, echarts) { + let lang = { + 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' + } + }, + dataView: { + title: 'Data View', + lang: ['Data View', 'Close', 'Refresh'] + }, + dataZoom: { + title: { + zoom: 'Zoom', + back: 'Zoom Reset' + } + }, + magicType: { + title: { + line: 'Switch to Line Chart', + bar: 'Switch to Bar Chart', + stack: 'Stack', + tiled: 'Tile' + } + }, + restore: { + title: 'Restore' + }, + 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' + } + }, + 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}.' + }, + 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: '.' + } + } + } + }; + + echarts.registerLocale('EN', lang); +}); diff --git a/src/langES.ts b/i18n/langES.ts similarity index 100% rename from src/langES.ts rename to i18n/langES.ts diff --git a/src/langFI.ts b/i18n/langFI.ts similarity index 100% rename from src/langFI.ts rename to i18n/langFI.ts diff --git a/src/langTH.ts b/i18n/langTH.ts similarity index 100% rename from src/langTH.ts rename to i18n/langTH.ts diff --git a/i18n/langZH.js b/i18n/langZH.js new file mode 100644 index 0000000000..5b2a4d94dc --- /dev/null +++ b/i18n/langZH.js @@ -0,0 +1,141 @@ +/* + * 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. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports', 'echarts'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports, require('echarts')); + } else { + // Browser globals + factory({}, root.echarts); + } +})(this, function(exports, echarts) { + let lang = { + + legend: { + selector: { + all: '全选', + inverse: '反选' + } + }, + toolbox: { + brush: { + title: { + rect: '矩形选择', + polygon: '圈选', + lineX: '横向选择', + lineY: '纵向选择', + keep: '保持选择', + clear: '清除选择' + } + }, + dataView: { + title: '数据视图', + lang: ['数据视图', '关闭', '刷新'] + }, + dataZoom: { + title: { + zoom: '区域缩放', + back: '区域缩放还原' + } + }, + magicType: { + title: { + line: '切换为折线图', + bar: '切换为柱状图', + stack: '切换为堆叠', + tiled: '切换为平铺' + } + }, + restore: { + title: '还原' + }, + saveAsImage: { + title: '保存为图片', + lang: ['右键另存为图片'] + } + }, + series: { + typeNames: { + pie: '饼图', + bar: '柱状图', + line: '折线图', + scatter: '散点图', + effectScatter: '涟漪散点图', + radar: '雷达图', + tree: '树图', + treemap: '矩形树图', + boxplot: '箱型图', + candlestick: 'K线图', + k: 'K线图', + heatmap: '热力图', + map: '地图', + parallel: '平行坐标图', + lines: '线图', + graph: '关系图', + sankey: '桑基图', + funnel: '漏斗图', + gauge: '仪表盘图', + pictorialBar: '象形柱图', + themeRiver: '主题河流图', + sunburst: '旭日图' + } + }, + aria: { + general: { + withTitle: '这是一个关于“{title}”的图表。', + withoutTitle: '这是一个图表,' + }, + series: { + single: { + prefix: '', + withName: '图表类型是{seriesType},表示{seriesName}。', + withoutName: '图表类型是{seriesType}。' + }, + multiple: { + prefix: '它由{seriesCount}个图表系列组成。', + withName: '第{seriesId}个系列是一个表示{seriesName}的{seriesType},', + withoutName: '第{seriesId}个系列是一个{seriesType},', + separator: { + middle: ';', + end: '。' + } + } + }, + data: { + allData: '其数据是——', + partialData: '其中,前{displayCnt}项是——', + withName: '{name}的数据是{value}', + withoutName: '{value}', + separator: { + middle: ',', + end: '' + } + } + } + }; + + echarts.registerLocale('ZH', lang); +}); diff --git a/src/component/legend/LegendModel.ts b/src/component/legend/LegendModel.ts index 290b7b348d..aba89156d2 100644 --- a/src/component/legend/LegendModel.ts +++ b/src/component/legend/LegendModel.ts @@ -20,7 +20,6 @@ import * as zrUtil from 'zrender/src/core/util'; import Model from '../../model/Model'; import {isNameSpecified} from '../../util/model'; -import lang from '../../lang'; import ComponentModel from '../../model/Component'; import { ComponentOption, @@ -35,18 +34,24 @@ import { import { Dictionary } from 'zrender/src/core/types'; import GlobalModel from '../../model/Global'; -const langSelector = lang.legend.selector; - -const defaultSelectorOption = { - all: { - type: 'all', - title: zrUtil.clone(langSelector.all) - }, - inverse: { - type: 'inverse', - title: zrUtil.clone(langSelector.inverse) - } +type LegendDefaultSelectorOptionsProps = { + type: string; + title: string; }; +const getDefaultSelectorOptions = function (ecModel: GlobalModel, type: string): LegendDefaultSelectorOptionsProps { + if(type === 'all') { + return { + type: 'all', + title: ecModel.getWithLocale(['legend', 'selector', 'all']) + } + } else if(type === 'inverse') { + return { + type: 'inverse', + title: ecModel.getWithLocale(['legend', 'selector', 'inverse']) + } + } +} + type SelectorType = 'all' | 'inverse'; export interface LegendSelectorButtonOption { @@ -201,6 +206,7 @@ class LegendModel extends ComponentMode _updateSelector(option: Ops) { let selector = option.selector; + const {ecModel} = this; if (selector === true) { selector = option.selector = ['all', 'inverse']; } @@ -208,7 +214,7 @@ class LegendModel extends ComponentMode zrUtil.each(selector, function (item, index) { zrUtil.isString(item) && (item = {type: item}); (selector as LegendSelectorButtonOption[])[index] = zrUtil.merge( - item, defaultSelectorOption[item.type] + item, getDefaultSelectorOptions(ecModel, item.type) ); }); } @@ -434,4 +440,4 @@ class LegendModel extends ComponentMode ComponentModel.registerClass(LegendModel); -export default LegendModel; \ No newline at end of file +export default LegendModel; diff --git a/src/component/toolbox/ToolboxModel.ts b/src/component/toolbox/ToolboxModel.ts index 4c25d8fc75..6c71ec709d 100644 --- a/src/component/toolbox/ToolboxModel.ts +++ b/src/component/toolbox/ToolboxModel.ts @@ -31,6 +31,7 @@ import { CommonTooltipOption, Dictionary } from '../../util/types'; +import GlobalModel from "../../model/Global"; export interface ToolboxTooltipFormatterParams { @@ -86,9 +87,13 @@ class ToolboxModel extends ComponentModel { optionUpdated() { super.optionUpdated.apply(this, arguments as any); + const {ecModel} = this; zrUtil.each(this.option.feature, function (featureOpt, featureName) { const Feature = featureManager.getFeature(featureName); + if(Feature.getDefaultOption) { + Feature.defaultOption = Feature.getDefaultOption(ecModel) + } Feature && zrUtil.merge(featureOpt, Feature.defaultOption); }); } @@ -147,4 +152,4 @@ class ToolboxModel extends ComponentModel { ComponentModel.registerClass(ToolboxModel); -export default ToolboxModel; \ No newline at end of file +export default ToolboxModel; diff --git a/src/component/toolbox/feature/Brush.ts b/src/component/toolbox/feature/Brush.ts index 984fa33772..c9e1208d5f 100644 --- a/src/component/toolbox/feature/Brush.ts +++ b/src/component/toolbox/feature/Brush.ts @@ -18,7 +18,6 @@ */ import * as zrUtil from 'zrender/src/core/util'; -import lang from '../../../lang'; import { ToolboxFeatureModel, ToolboxFeatureOption, @@ -30,8 +29,6 @@ import ExtensionAPI from '../../../ExtensionAPI'; import BrushModel from '../../brush/BrushModel'; import { BrushTypeUncertain } from '../../helper/BrushController'; -const brushLang = lang.toolbox.brush; - const ICON_TYPES = ['rect', 'polygon', 'lineX', 'lineY', 'keep', 'clear'] as const; type IconType = typeof ICON_TYPES[number]; @@ -132,24 +129,28 @@ class BrushFeature extends ToolboxFeature { } }; - static defaultOption: ToolboxBrushFeatureOption = { - show: true, - type: ICON_TYPES.slice(), - icon: { - /* eslint-disable */ - rect: 'M7.3,34.7 M0.4,10V-0.2h9.8 M89.6,10V-0.2h-9.8 M0.4,60v10.2h9.8 M89.6,60v10.2h-9.8 M12.3,22.4V10.5h13.1 M33.6,10.5h7.8 M49.1,10.5h7.8 M77.5,22.4V10.5h-13 M12.3,31.1v8.2 M77.7,31.1v8.2 M12.3,47.6v11.9h13.1 M33.6,59.5h7.6 M49.1,59.5 h7.7 M77.5,47.6v11.9h-13', // jshint ignore:line - polygon: 'M55.2,34.9c1.7,0,3.1,1.4,3.1,3.1s-1.4,3.1-3.1,3.1 s-3.1-1.4-3.1-3.1S53.5,34.9,55.2,34.9z M50.4,51c1.7,0,3.1,1.4,3.1,3.1c0,1.7-1.4,3.1-3.1,3.1c-1.7,0-3.1-1.4-3.1-3.1 C47.3,52.4,48.7,51,50.4,51z M55.6,37.1l1.5-7.8 M60.1,13.5l1.6-8.7l-7.8,4 M59,19l-1,5.3 M24,16.1l6.4,4.9l6.4-3.3 M48.5,11.6 l-5.9,3.1 M19.1,12.8L9.7,5.1l1.1,7.7 M13.4,29.8l1,7.3l6.6,1.6 M11.6,18.4l1,6.1 M32.8,41.9 M26.6,40.4 M27.3,40.2l6.1,1.6 M49.9,52.1l-5.6-7.6l-4.9-1.2', // jshint ignore:line - lineX: 'M15.2,30 M19.7,15.6V1.9H29 M34.8,1.9H40.4 M55.3,15.6V1.9H45.9 M19.7,44.4V58.1H29 M34.8,58.1H40.4 M55.3,44.4 V58.1H45.9 M12.5,20.3l-9.4,9.6l9.6,9.8 M3.1,29.9h16.5 M62.5,20.3l9.4,9.6L62.3,39.7 M71.9,29.9H55.4', // jshint ignore:line - lineY: 'M38.8,7.7 M52.7,12h13.2v9 M65.9,26.6V32 M52.7,46.3h13.2v-9 M24.9,12H11.8v9 M11.8,26.6V32 M24.9,46.3H11.8v-9 M48.2,5.1l-9.3-9l-9.4,9.2 M38.9-3.9V12 M48.2,53.3l-9.3,9l-9.4-9.2 M38.9,62.3V46.4', // jshint ignore:line - keep: 'M4,10.5V1h10.3 M20.7,1h6.1 M33,1h6.1 M55.4,10.5V1H45.2 M4,17.3v6.6 M55.6,17.3v6.6 M4,30.5V40h10.3 M20.7,40 h6.1 M33,40h6.1 M55.4,30.5V40H45.2 M21,18.9h62.9v48.6H21V18.9z', // jshint ignore:line - clear: 'M22,14.7l30.9,31 M52.9,14.7L22,45.7 M4.7,16.8V4.2h13.1 M26,4.2h7.8 M41.6,4.2h7.8 M70.3,16.8V4.2H57.2 M4.7,25.9v8.6 M70.3,25.9v8.6 M4.7,43.2v12.6h13.1 M26,55.8h7.8 M41.6,55.8h7.8 M70.3,43.2v12.6H57.2' // jshint ignore:line - /* eslint-enable */ - }, - // `rect`, `polygon`, `lineX`, `lineY`, `keep`, `clear` - title: zrUtil.clone(brushLang.title) - }; + static getDefaultOption(ecModel: GlobalModel) { + const defaultOption: ToolboxBrushFeatureOption = { + show: true, + type: ICON_TYPES.slice(), + icon: { + /* eslint-disable */ + rect: 'M7.3,34.7 M0.4,10V-0.2h9.8 M89.6,10V-0.2h-9.8 M0.4,60v10.2h9.8 M89.6,60v10.2h-9.8 M12.3,22.4V10.5h13.1 M33.6,10.5h7.8 M49.1,10.5h7.8 M77.5,22.4V10.5h-13 M12.3,31.1v8.2 M77.7,31.1v8.2 M12.3,47.6v11.9h13.1 M33.6,59.5h7.6 M49.1,59.5 h7.7 M77.5,47.6v11.9h-13', // jshint ignore:line + polygon: 'M55.2,34.9c1.7,0,3.1,1.4,3.1,3.1s-1.4,3.1-3.1,3.1 s-3.1-1.4-3.1-3.1S53.5,34.9,55.2,34.9z M50.4,51c1.7,0,3.1,1.4,3.1,3.1c0,1.7-1.4,3.1-3.1,3.1c-1.7,0-3.1-1.4-3.1-3.1 C47.3,52.4,48.7,51,50.4,51z M55.6,37.1l1.5-7.8 M60.1,13.5l1.6-8.7l-7.8,4 M59,19l-1,5.3 M24,16.1l6.4,4.9l6.4-3.3 M48.5,11.6 l-5.9,3.1 M19.1,12.8L9.7,5.1l1.1,7.7 M13.4,29.8l1,7.3l6.6,1.6 M11.6,18.4l1,6.1 M32.8,41.9 M26.6,40.4 M27.3,40.2l6.1,1.6 M49.9,52.1l-5.6-7.6l-4.9-1.2', // jshint ignore:line + lineX: 'M15.2,30 M19.7,15.6V1.9H29 M34.8,1.9H40.4 M55.3,15.6V1.9H45.9 M19.7,44.4V58.1H29 M34.8,58.1H40.4 M55.3,44.4 V58.1H45.9 M12.5,20.3l-9.4,9.6l9.6,9.8 M3.1,29.9h16.5 M62.5,20.3l9.4,9.6L62.3,39.7 M71.9,29.9H55.4', // jshint ignore:line + lineY: 'M38.8,7.7 M52.7,12h13.2v9 M65.9,26.6V32 M52.7,46.3h13.2v-9 M24.9,12H11.8v9 M11.8,26.6V32 M24.9,46.3H11.8v-9 M48.2,5.1l-9.3-9l-9.4,9.2 M38.9-3.9V12 M48.2,53.3l-9.3,9l-9.4-9.2 M38.9,62.3V46.4', // jshint ignore:line + keep: 'M4,10.5V1h10.3 M20.7,1h6.1 M33,1h6.1 M55.4,10.5V1H45.2 M4,17.3v6.6 M55.6,17.3v6.6 M4,30.5V40h10.3 M20.7,40 h6.1 M33,40h6.1 M55.4,30.5V40H45.2 M21,18.9h62.9v48.6H21V18.9z', // jshint ignore:line + clear: 'M22,14.7l30.9,31 M52.9,14.7L22,45.7 M4.7,16.8V4.2h13.1 M26,4.2h7.8 M41.6,4.2h7.8 M70.3,16.8V4.2H57.2 M4.7,25.9v8.6 M70.3,25.9v8.6 M4.7,43.2v12.6h13.1 M26,55.8h7.8 M41.6,55.8h7.8 M70.3,43.2v12.6H57.2' // jshint ignore:line + /* eslint-enable */ + }, + // `rect`, `polygon`, `lineX`, `lineY`, `keep`, `clear` + title: ecModel.getWithLocale(['toolbox', 'brush', 'title']) + } + + return defaultOption; + } } registerFeature('brush', BrushFeature); -export default BrushFeature; \ No newline at end of file +export default BrushFeature; diff --git a/src/component/toolbox/feature/DataView.ts b/src/component/toolbox/feature/DataView.ts index 690f7d4ada..ddf4231f50 100644 --- a/src/component/toolbox/feature/DataView.ts +++ b/src/component/toolbox/feature/DataView.ts @@ -19,7 +19,6 @@ import * as echarts from '../../../echarts'; import * as zrUtil from 'zrender/src/core/util'; -import lang from '../../../lang'; import GlobalModel from '../../../model/Global'; import SeriesModel from '../../../model/Series'; import { ToolboxFeature, registerFeature, ToolboxFeatureOption } from '../featureManager'; @@ -28,8 +27,7 @@ import ExtensionAPI from '../../../ExtensionAPI'; import { addEventListener } from 'zrender/src/core/event'; import Axis from '../../../coord/Axis'; import Cartesian2D from '../../../coord/cartesian/Cartesian2D'; - -const dataViewLang = lang.toolbox.dataView; +import {ToolboxSaveAsImageFeatureOption} from "./SaveAsImage"; const BLOCK_SPLITER = new Array(60).join('-'); const ITEM_SPLITER = '\t'; @@ -423,23 +421,27 @@ class DataView extends ToolboxFeature { this.remove(ecModel, api); } - static defaultOption: ToolboxDataViewFeatureOption = { - show: true, - readOnly: false, - optionToContent: null, - contentToOption: null, - - // eslint-disable-next-line - icon: 'M17.5,17.3H33 M17.5,17.3H33 M45.4,29.5h-28 M11.5,2v56H51V14.8L38.4,2H11.5z M38.4,2.2v12.7H51 M45.4,41.7h-28', - title: zrUtil.clone(dataViewLang.title), - lang: zrUtil.clone(dataViewLang.lang), - backgroundColor: '#fff', - textColor: '#000', - textareaColor: '#fff', - textareaBorderColor: '#333', - buttonColor: '#c23531', - buttonTextColor: '#fff' - }; + static getDefaultOption(ecModel: GlobalModel) { + const defaultOption: ToolboxDataViewFeatureOption = { + show: true, + readOnly: false, + optionToContent: null, + contentToOption: null, + + // eslint-disable-next-line + icon: 'M17.5,17.3H33 M17.5,17.3H33 M45.4,29.5h-28 M11.5,2v56H51V14.8L38.4,2H11.5z M38.4,2.2v12.7H51 M45.4,41.7h-28', + title: ecModel.getWithLocale(['toolbox', 'dataView', 'title']), + lang: ecModel.getWithLocale(['toolbox', 'dataView', 'lang']), + backgroundColor: '#fff', + textColor: '#000', + textareaColor: '#fff', + textareaBorderColor: '#333', + buttonColor: '#c23531', + buttonTextColor: '#fff' + } + + return defaultOption; + } } /** @@ -495,4 +497,4 @@ echarts.registerAction({ }, payload.newOption)); }); -export default DataView; \ No newline at end of file +export default DataView; diff --git a/src/component/toolbox/feature/DataZoom.ts b/src/component/toolbox/feature/DataZoom.ts index a69b92f8e2..a42f2829cd 100644 --- a/src/component/toolbox/feature/DataZoom.ts +++ b/src/component/toolbox/feature/DataZoom.ts @@ -24,7 +24,6 @@ import BrushController, { BrushControllerEvents, BrushDimensionMinMax } from '.. import BrushTargetManager, { BrushTargetInfoCartesian2D } from '../../helper/BrushTargetManager'; import * as history from '../../dataZoom/history'; import sliderMove from '../../helper/sliderMove'; -import lang from '../../../lang'; // Use dataZoomSelect import '../../dataZoomSelect'; import { @@ -51,7 +50,6 @@ import { registerInternalOptionCreator } from '../../../model/internalComponentC import ComponentModel from '../../../model/Component'; -const dataZoomLang = lang.toolbox.dataZoom; const each = zrUtil.each; const DATA_ZOOM_ID_BASE = makeInternalComponentId('toolbox-dataZoom_'); @@ -206,17 +204,21 @@ class DataZoomFeature extends ToolboxFeature { }); } - static defaultOption: ToolboxDataZoomFeatureOption = { - show: true, - filterMode: 'filter', - // Icon group - icon: { - zoom: 'M0,13.5h26.9 M13.5,26.9V0 M32.1,13.5H58V58H13.5 V32.1', - back: 'M22,1.4L9.9,13.5l12.3,12.3 M10.3,13.5H54.9v44.6 H10.3v-26' - }, - // `zoom`, `back` - title: zrUtil.clone(dataZoomLang.title) - }; + static getDefaultOption(ecModel: GlobalModel) { + const defaultOption: ToolboxDataZoomFeatureOption = { + show: true, + filterMode: 'filter', + // Icon group + icon: { + zoom: 'M0,13.5h26.9 M13.5,26.9V0 M32.1,13.5H58V58H13.5 V32.1', + back: 'M22,1.4L9.9,13.5l12.3,12.3 M10.3,13.5H54.9v44.6 H10.3v-26' + }, + // `zoom`, `back` + title: ecModel.getWithLocale(['toolbox', 'dataZoom', 'title']), + } + + return defaultOption; + } } const handlers: { [key in IconType]: (this: DataZoomFeature) => void } = { diff --git a/src/component/toolbox/feature/MagicType.ts b/src/component/toolbox/feature/MagicType.ts index b5b3e0ff00..1fd0da9f21 100644 --- a/src/component/toolbox/feature/MagicType.ts +++ b/src/component/toolbox/feature/MagicType.ts @@ -19,7 +19,6 @@ import * as echarts from '../../../echarts'; import * as zrUtil from 'zrender/src/core/util'; -import lang from '../../../lang'; import {ToolboxFeature, ToolboxFeatureOption, ToolboxFeatureModel, registerFeature} from '../featureManager'; import { SeriesOption, ECUnitOption } from '../../../util/types'; import GlobalModel from '../../../model/Global'; @@ -27,7 +26,6 @@ import ExtensionAPI from '../../../ExtensionAPI'; import SeriesModel from '../../../model/Series'; import { SINGLE_REFERRING } from '../../../util/model'; -const magicTypeLang = lang.toolbox.magicType; const INNER_STACK_KEYWORD = '__ec_magicType_stack__' as const; const ICON_TYPES = ['line', 'bar', 'stack'] as const; @@ -74,21 +72,25 @@ class MagicType extends ToolboxFeature { return icons; } - static defaultOption: ToolboxMagicTypeFeatureOption = { - show: true, - type: [], - // Icon group - icon: { - line: 'M4.1,28.9h7.1l9.3-22l7.4,38l9.7-19.7l3,12.8h14.9M4.1,58h51.4', - bar: 'M6.7,22.9h10V48h-10V22.9zM24.9,13h10v35h-10V13zM43.2,2h10v46h-10V2zM3.1,58h53.7', - // eslint-disable-next-line - stack: 'M8.2,38.4l-8.4,4.1l30.6,15.3L60,42.5l-8.1-4.1l-21.5,11L8.2,38.4z M51.9,30l-8.1,4.2l-13.4,6.9l-13.9-6.9L8.2,30l-8.4,4.2l8.4,4.2l22.2,11l21.5-11l8.1-4.2L51.9,30z M51.9,21.7l-8.1,4.2L35.7,30l-5.3,2.8L24.9,30l-8.4-4.1l-8.3-4.2l-8.4,4.2L8.2,30l8.3,4.2l13.9,6.9l13.4-6.9l8.1-4.2l8.1-4.1L51.9,21.7zM30.4,2.2L-0.2,17.5l8.4,4.1l8.3,4.2l8.4,4.2l5.5,2.7l5.3-2.7l8.1-4.2l8.1-4.2l8.1-4.1L30.4,2.2z' // jshint ignore:line - }, - // `line`, `bar`, `stack`, `tiled` - title: zrUtil.clone(magicTypeLang.title), - option: {}, - seriesIndex: {} - }; + static getDefaultOption(ecModel: GlobalModel) { + const defaultOption: ToolboxMagicTypeFeatureOption = { + show: true, + type: [], + // Icon group + icon: { + line: 'M4.1,28.9h7.1l9.3-22l7.4,38l9.7-19.7l3,12.8h14.9M4.1,58h51.4', + bar: 'M6.7,22.9h10V48h-10V22.9zM24.9,13h10v35h-10V13zM43.2,2h10v46h-10V2zM3.1,58h53.7', + // eslint-disable-next-line + stack: 'M8.2,38.4l-8.4,4.1l30.6,15.3L60,42.5l-8.1-4.1l-21.5,11L8.2,38.4z M51.9,30l-8.1,4.2l-13.4,6.9l-13.9-6.9L8.2,30l-8.4,4.2l8.4,4.2l22.2,11l21.5-11l8.1-4.2L51.9,30z M51.9,21.7l-8.1,4.2L35.7,30l-5.3,2.8L24.9,30l-8.4-4.1l-8.3-4.2l-8.4,4.2L8.2,30l8.3,4.2l13.9,6.9l13.4-6.9l8.1-4.2l8.1-4.1L51.9,21.7zM30.4,2.2L-0.2,17.5l8.4,4.1l8.3,4.2l8.4,4.2l5.5,2.7l5.3-2.7l8.1-4.2l8.1-4.2l8.1-4.1L30.4,2.2z' // jshint ignore:line + }, + // `line`, `bar`, `stack`, `tiled` + title: ecModel.getWithLocale(['toolbox', 'magicTypeLang', 'title']), + option: {}, + seriesIndex: {} + } + + return defaultOption; + } onclick(ecModel: GlobalModel, api: ExtensionAPI, type: IconType) { const model = this.model; @@ -153,11 +155,13 @@ class MagicType extends ToolboxFeature { // Change title of stack if (type === 'stack') { const seriesOptions = newOption.series as (SeriesOption & { stack: string })[]; + const titldLang = ecModel.getWithLocale(['toolbox', 'magicTypeLang', 'title', 'tiled']); + const titleLang = ecModel.getWithLocale(['toolbox', 'magicTypeLang', 'title']); const isStack = seriesOptions && seriesOptions[0] && seriesOptions[0].stack === INNER_STACK_KEYWORD; newTitle = isStack - ? zrUtil.merge({ stack: magicTypeLang.title.tiled }, magicTypeLang.title) - : zrUtil.clone(magicTypeLang.title); + ? zrUtil.merge({ stack: titldLang }, titleLang) + : zrUtil.clone(titleLang); } api.dispatchAction({ @@ -234,4 +238,4 @@ echarts.registerAction({ registerFeature('magicType', MagicType); -export default MagicType; \ No newline at end of file +export default MagicType; diff --git a/src/component/toolbox/feature/Restore.ts b/src/component/toolbox/feature/Restore.ts index 9e650bddb8..b8a2c6968a 100644 --- a/src/component/toolbox/feature/Restore.ts +++ b/src/component/toolbox/feature/Restore.ts @@ -19,13 +19,10 @@ import * as echarts from '../../../echarts'; import * as history from '../../dataZoom/history'; -import lang from '../../../lang'; import { ToolboxFeatureOption, ToolboxFeature, registerFeature } from '../featureManager'; import ExtensionAPI from '../../../ExtensionAPI'; import GlobalModel from '../../../model/Global'; -const restoreLang = lang.toolbox.restore; - export interface ToolboxRestoreFeatureOption extends ToolboxFeatureOption { icon?: string title?: string @@ -42,12 +39,16 @@ class RestoreOption extends ToolboxFeature { }); } - static defaultOption: ToolboxRestoreFeatureOption = { - show: true, - // eslint-disable-next-line - icon: 'M3.8,33.4 M47,18.9h9.8V8.7 M56.3,20.1 C52.1,9,40.5,0.6,26.8,2.1C12.6,3.7,1.6,16.2,2.1,30.6 M13,41.1H3.1v10.2 M3.7,39.9c4.2,11.1,15.8,19.5,29.5,18 c14.2-1.6,25.2-14.1,24.7-28.5', - title: restoreLang.title - }; + static getDefaultOption(ecModel: GlobalModel) { + const defaultOption: ToolboxRestoreFeatureOption = { + show: true, + // eslint-disable-next-line + icon: 'M3.8,33.4 M47,18.9h9.8V8.7 M56.3,20.1 C52.1,9,40.5,0.6,26.8,2.1C12.6,3.7,1.6,16.2,2.1,30.6 M13,41.1H3.1v10.2 M3.7,39.9c4.2,11.1,15.8,19.5,29.5,18 c14.2-1.6,25.2-14.1,24.7-28.5', + title: ecModel.getWithLocale(['toolbox', 'restore', 'title']), + } + + return defaultOption; + } } registerFeature('restore', RestoreOption); @@ -57,4 +58,4 @@ echarts.registerAction( function (payload, ecModel) { ecModel.resetOption('recreate'); } -); \ No newline at end of file +); diff --git a/src/component/toolbox/feature/SaveAsImage.ts b/src/component/toolbox/feature/SaveAsImage.ts index f90d7185ab..f97827a04b 100644 --- a/src/component/toolbox/feature/SaveAsImage.ts +++ b/src/component/toolbox/feature/SaveAsImage.ts @@ -20,14 +20,11 @@ /* global Uint8Array */ import env from 'zrender/src/core/env'; -import lang from '../../../lang'; import { ToolboxFeature, ToolboxFeatureOption, registerFeature } from '../featureManager'; import { ZRColor } from '../../../util/types'; import GlobalModel from '../../../model/Global'; import ExtensionAPI from '../../../ExtensionAPI'; -const saveAsImageLang = lang.toolbox.saveAsImage; - export interface ToolboxSaveAsImageFeatureOption extends ToolboxFeatureOption { icon?: string title?: string @@ -97,20 +94,25 @@ class SaveAsImage extends ToolboxFeature { } } - static defaultOption: ToolboxSaveAsImageFeatureOption = { - show: true, - icon: 'M4.7,22.9L29.3,45.5L54.7,23.4M4.6,43.6L4.6,58L53.8,58L53.8,43.6M29.2,45.1L29.2,0', - title: saveAsImageLang.title, - type: 'png', - // Default use option.backgroundColor - // backgroundColor: '#fff', - connectedBackgroundColor: '#fff', - name: '', - excludeComponents: ['toolbox'], - pixelRatio: 1, - lang: saveAsImageLang.lang.slice() - }; + static getDefaultOption(ecModel: GlobalModel) { + const defaultOption: ToolboxSaveAsImageFeatureOption = { + show: true, + icon: 'M4.7,22.9L29.3,45.5L54.7,23.4M4.6,43.6L4.6,58L53.8,58L53.8,43.6M29.2,45.1L29.2,0', + title: ecModel.getWithLocale(['toolbox', 'saveAsImage', 'title']), + type: 'png', + // Default use option.backgroundColor + // backgroundColor: '#fff', + connectedBackgroundColor: '#fff', + name: '', + excludeComponents: ['toolbox'], + pixelRatio: 1, + lang: ecModel.getWithLocale(['toolbox', 'saveAsImage', 'lang'], null, (t) => t.slice()) + } + + return defaultOption; + } } + SaveAsImage.prototype.unusable = !env.canvasSupported; registerFeature('saveAsImage', SaveAsImage); diff --git a/src/component/toolbox/featureManager.ts b/src/component/toolbox/featureManager.ts index 52367cd240..756e013617 100644 --- a/src/component/toolbox/featureManager.ts +++ b/src/component/toolbox/featureManager.ts @@ -106,7 +106,8 @@ type ToolboxFeatureCtor = { /** * Static defaultOption property */ - defaultOption: ToolboxFeatureOption + defaultOption?: ToolboxFeatureOption + getDefaultOption?: (ecModel: GlobalModel) => ToolboxFeatureOption }; const features: Dictionary = {}; diff --git a/src/echarts.ts b/src/echarts.ts index 64e4d89702..73c883b7e4 100644 --- a/src/echarts.ts +++ b/src/echarts.ts @@ -76,7 +76,7 @@ import { ActionHandler, ActionInfo, OptionPreprocessor, PostUpdater, LoadingEffect, LoadingEffectCreator, StageHandlerInternal, StageHandlerOverallReset, StageHandler, - ViewRootGroup, DimensionDefinitionLoose, ECEventData, ThemeOption, + ViewRootGroup, DimensionDefinitionLoose, ECEventData, ThemeOption, LocaleOption, ECOption, ECUnitOption, ZRColor, @@ -274,6 +274,8 @@ class ECharts extends Eventful { private _theme: ThemeOption; + private _locale: LocaleOption; + private _chartsViews: ChartView[] = []; private _chartsMap: {[viewId: string]: ChartView} = {}; @@ -310,6 +312,7 @@ class ECharts extends Eventful { dom: HTMLElement, // Theme name or themeOption. theme?: string | ThemeOption, + locale?: string | LocaleOption, opts?: { renderer?: RendererType, devicePixelRatio?: number, @@ -349,6 +352,8 @@ class ECharts extends Eventful { theme && backwardCompat(theme as ECUnitOption, true); this._theme = theme; + this._locale = typeof locale === 'string' ? localeStorage[locale || 'ZH'] : zrUtil.clone(locale); + console.log(this._locale); this._coordSysMgr = new CoordinateSystemManager(); @@ -504,7 +509,7 @@ class ECharts extends Eventful { const theme = this._theme; const ecModel = this._model = new GlobalModel(); ecModel.scheduler = this._scheduler; - ecModel.init(null, null, null, theme, optionManager); + ecModel.init(null, null, null, theme, this._locale, optionManager); } this._model.setOption(option, {replaceMerge: replaceMerge}, optionPreprocessorFuncs); @@ -2301,6 +2306,8 @@ const visualFuncs: StageHandlerInternal[] = []; const themeStorage: {[themeName: string]: ThemeOption} = {}; +const localeStorage: {[localeName: string]: LocaleOption} = {}; + const loadingEffects: {[effectName: string]: LoadingEffectCreator} = {}; const instances: {[id: string]: ECharts} = {}; @@ -2322,6 +2329,7 @@ const DOM_ATTRIBUTE_KEY = '_echarts_instance_'; export function init( dom: HTMLElement, theme?: string | object, + locale?: string | object, opts?: { renderer?: RendererType, devicePixelRatio?: number, @@ -2368,7 +2376,7 @@ export function init( } } - const chart = new ECharts(dom, theme, opts); + const chart = new ECharts(dom, theme, locale, opts); chart.id = 'ec_' + idBase++; instances[chart.id] = chart; @@ -2459,6 +2467,11 @@ export function registerTheme(name: string, theme: ThemeOption): void { themeStorage[name] = theme; } +export function registerLocale(name: string, locale: LocaleOption): void { + localeStorage[name] = locale; + console.log('localeStorage', localeStorage); +} + /** * Register option preprocessor */ diff --git a/src/lang.ts b/src/lang.ts deleted file mode 100644 index b369139b8d..0000000000 --- a/src/lang.ts +++ /dev/null @@ -1,126 +0,0 @@ -/* -* 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. -*/ - -/** - * Language: (Simplified) Chinese. - */ - -export default { - legend: { - selector: { - all: '全选', - inverse: '反选' - } - }, - toolbox: { - brush: { - title: { - rect: '矩形选择', - polygon: '圈选', - lineX: '横向选择', - lineY: '纵向选择', - keep: '保持选择', - clear: '清除选择' - } - }, - dataView: { - title: '数据视图', - lang: ['数据视图', '关闭', '刷新'] - }, - dataZoom: { - title: { - zoom: '区域缩放', - back: '区域缩放还原' - } - }, - magicType: { - title: { - line: '切换为折线图', - bar: '切换为柱状图', - stack: '切换为堆叠', - tiled: '切换为平铺' - } - }, - restore: { - title: '还原' - }, - saveAsImage: { - title: '保存为图片', - lang: ['右键另存为图片'] - } - }, - series: { - typeNames: { - pie: '饼图', - bar: '柱状图', - line: '折线图', - scatter: '散点图', - effectScatter: '涟漪散点图', - radar: '雷达图', - tree: '树图', - treemap: '矩形树图', - boxplot: '箱型图', - candlestick: 'K线图', - k: 'K线图', - heatmap: '热力图', - map: '地图', - parallel: '平行坐标图', - lines: '线图', - graph: '关系图', - sankey: '桑基图', - funnel: '漏斗图', - gauge: '仪表盘图', - pictorialBar: '象形柱图', - themeRiver: '主题河流图', - sunburst: '旭日图' - } - }, - aria: { - general: { - withTitle: '这是一个关于“{title}”的图表。', - withoutTitle: '这是一个图表,' - }, - series: { - single: { - prefix: '', - withName: '图表类型是{seriesType},表示{seriesName}。', - withoutName: '图表类型是{seriesType}。' - }, - multiple: { - prefix: '它由{seriesCount}个图表系列组成。', - withName: '第{seriesId}个系列是一个表示{seriesName}的{seriesType},', - withoutName: '第{seriesId}个系列是一个{seriesType},', - separator: { - middle: ';', - end: '。' - } - } - }, - data: { - allData: '其数据是——', - partialData: '其中,前{displayCnt}项是——', - withName: '{name}的数据是{value}', - withoutName: '{value}', - separator: { - middle: ',', - end: '' - } - } - } -}; diff --git a/src/langEN.ts b/src/langEN.ts deleted file mode 100644 index 0df1872d6f..0000000000 --- a/src/langEN.ts +++ /dev/null @@ -1,126 +0,0 @@ -/* -* 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. -*/ - -/** - * Language: English. - */ - -export default { - 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' - } - }, - dataView: { - title: 'Data View', - lang: ['Data View', 'Close', 'Refresh'] - }, - dataZoom: { - title: { - zoom: 'Zoom', - back: 'Zoom Reset' - } - }, - magicType: { - title: { - line: 'Switch to Line Chart', - bar: 'Switch to Bar Chart', - stack: 'Stack', - tiled: 'Tile' - } - }, - restore: { - title: 'Restore' - }, - 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' - } - }, - 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}.' - }, - 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: '.' - } - } - } -}; diff --git a/src/model/Global.ts b/src/model/Global.ts index ff220f85b8..d9109d0236 100644 --- a/src/model/Global.ts +++ b/src/model/Global.ts @@ -53,11 +53,12 @@ import { ThemeOption, ComponentOption, ComponentMainType, - ComponentSubType + ComponentSubType, LocaleOption } from '../util/types'; import OptionManager from './OptionManager'; import Scheduler from '../stream/Scheduler'; import { concatInternalOptions } from './internalComponentCreator'; +import {Dictionary} from "zrender/src/core/types"; export interface GlobalModelSetOptionOpts { replaceMerge: ComponentMainType | ComponentMainType[]; @@ -80,6 +81,8 @@ class GlobalModel extends Model { private _theme: Model; + private _locale: object; + private _optionManager: OptionManager; private _componentsMap: HashMap; @@ -119,11 +122,14 @@ class GlobalModel extends Model { parentModel: Model, ecModel: GlobalModel, theme: object, + locale: object, optionManager: OptionManager ): void { theme = theme || {}; this.option = null; // Mark as not initialized. this._theme = new Model(theme); + console.log('init', locale) + this._locale = locale; this._optionManager = optionManager; } @@ -417,6 +423,25 @@ class GlobalModel extends Model { return this._theme; } + getLocale(): LocaleOption { + return this._locale; + } + + getWithLocale(localePosition: Array, optionsPosition?: Array, localeHandlerFn?: (text: string) => string): any { + console.log(optionsPosition, localePosition); + const locale = this.getLocale() + let localeText: string | any; + localePosition.map(t => { + localeText = localeText ? localeText[t] : locale[t]; + }) + + if(localeHandlerFn) { + localeText = localeHandlerFn(localeText); + } + console.log(localeText); + return localeText; + } + setUpdatePayload(payload: Payload) { this._payload = payload; } diff --git a/src/util/types.ts b/src/util/types.ts index 0c7cf8413a..d276ad1bfb 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -470,6 +470,7 @@ export type OptionDataValueDate = Date | string | number; // export type ModelOption = Dictionary | any[] | string | number | boolean | ((...args: any) => any); export type ModelOption = any; export type ThemeOption = Dictionary; +export type LocaleOption = Dictionary; export type DisplayState = 'normal' | 'emphasis' | 'blur' | 'select'; export type DisplayStateNonNormal = Exclude; diff --git a/src/visual/aria.ts b/src/visual/aria.ts index 7e9b00acbb..aa75400ef6 100644 --- a/src/visual/aria.ts +++ b/src/visual/aria.ts @@ -145,7 +145,7 @@ export default function (dom, ecModel) { const userConfig = ariaModel.get(path); if (userConfig == null) { const pathArr = path.split('.'); - let result = lang.aria; + let result = ecModel.getWithLocale(['aria']); for (let i = 0; i < pathArr.length; ++i) { result = result[pathArr[i]]; } @@ -165,6 +165,6 @@ export default function (dom, ecModel) { } function getSeriesTypeName(type) { - return lang.series.typeNames[type] || '自定义图'; + return ecModel.getWithLocale(['series', 'typeNames'])[type] || '自定义图'; } } diff --git a/test/lang.html b/test/lang.html new file mode 100644 index 0000000000..a498ab3ccc --- /dev/null +++ b/test/lang.html @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + From 256ff11f60a7dbf786c9c7b91ac23dd867496f85 Mon Sep 17 00:00:00 2001 From: zakwu <123537200@qq.com> Date: Tue, 28 Jul 2020 11:50:22 +0800 Subject: [PATCH 02/14] feat(i18n): change i18n with build, and change the init api --- build/build-i18n.js | 69 +++++++++++++++++++++ build/build.js | 3 + i18n/langEN.js | 144 -------------------------------------------- i18n/langEN.json | 109 +++++++++++++++++++++++++++++++++ i18n/langZH.js | 141 ------------------------------------------- i18n/langZH.json | 109 +++++++++++++++++++++++++++++++++ package.json | 3 +- src/echarts.ts | 20 ++++-- src/model/Global.ts | 5 +- test/lang.html | 47 +++++++++++++-- 10 files changed, 351 insertions(+), 299 deletions(-) create mode 100644 build/build-i18n.js delete mode 100644 i18n/langEN.js create mode 100644 i18n/langEN.json delete mode 100644 i18n/langZH.js create mode 100644 i18n/langZH.json diff --git a/build/build-i18n.js b/build/build-i18n.js new file mode 100644 index 0000000000..7a768ea72e --- /dev/null +++ b/build/build-i18n.js @@ -0,0 +1,69 @@ +const fs = require('fs'); + +const outFilePath = './i18n'; +const umdWrapperHead = ` +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports); + } else { + // Browser globals + factory({}); + } +})(this, function(exports) { +var lang =`; + +const umdWrapperHeadWithEcharts = ` +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports', 'echarts'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports, require('echarts')); + } else { + // Browser globals + factory({}, root.echarts); + } +})(this, function(exports, echarts) { +var lang =`; + +const umdWrapperTail = ` +});`; + +async function buildI18nWrap() { + const targetDir = './i18n'; + const files = fs.readdirSync(targetDir); + files.forEach(t => { + if(!t.startsWith('lang') || !t.endsWith('json')) return; + const fileName = t.substring(0, t.length - 5); + console.log(fileName + ' is building...'); + const type = t.substr(-7, 2); + const echartsRegister = ` + echarts.registerLocale('${type}', lang); + `; + const pureExports = ` + exports.lang = lang; + `; + 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(outFilePath + '/' + fileName + '.ts', 'export default ' + code, 'utf-8'); + console.log(fileName + ' done'); + }) +} + +buildI18nWrap(); + +module.exports = { + buildI18n: buildI18nWrap +}; diff --git a/build/build.js b/build/build.js index f88d256aeb..436d9dc9f5 100755 --- a/build/build.js +++ b/build/build.js @@ -30,6 +30,7 @@ const ecLangPlugin = require('./ec-lang-rollup-plugin'); const prePublish = require('./pre-publish'); const recheckDEV = require('./remove-dev').recheckDEV; const assert = require('assert'); +const {buildI18n} = require('./build-i18n') async function run() { @@ -274,6 +275,8 @@ function getPath(relativePath) { * ] */ async function build(configs) { + // buildI18n JSON before build when build + buildI18n(); // ensureZRenderCode.prepare(); diff --git a/i18n/langEN.js b/i18n/langEN.js deleted file mode 100644 index ebba3a159b..0000000000 --- a/i18n/langEN.js +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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. - */ - -/** - * Language: English. - */ - -(function(root, factory) { - if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define(['exports', 'echarts'], factory); - } else if ( - typeof exports === 'object' && - typeof exports.nodeName !== 'string' - ) { - // CommonJS - factory(exports, require('echarts')); - } else { - // Browser globals - factory({}, root.echarts); - } -})(this, function(exports, echarts) { - let lang = { - 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' - } - }, - dataView: { - title: 'Data View', - lang: ['Data View', 'Close', 'Refresh'] - }, - dataZoom: { - title: { - zoom: 'Zoom', - back: 'Zoom Reset' - } - }, - magicType: { - title: { - line: 'Switch to Line Chart', - bar: 'Switch to Bar Chart', - stack: 'Stack', - tiled: 'Tile' - } - }, - restore: { - title: 'Restore' - }, - 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' - } - }, - 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}.' - }, - 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: '.' - } - } - } - }; - - echarts.registerLocale('EN', lang); -}); diff --git a/i18n/langEN.json b/i18n/langEN.json new file mode 100644 index 0000000000..2a41e5af2a --- /dev/null +++ b/i18n/langEN.json @@ -0,0 +1,109 @@ +{ + "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" + } + }, + "dataView": { + "title": "Data View", + "lang": [ + "Data View", + "Close", + "Refresh" + ] + }, + "dataZoom": { + "title": { + "zoom": "Zoom", + "back": "Zoom Reset" + } + }, + "magicType": { + "title": { + "line": "Switch to Line Chart", + "bar": "Switch to Bar Chart", + "stack": "Stack", + "tiled": "Tile" + } + }, + "restore": { + "title": "Restore" + }, + "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" + } + }, + "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}." + }, + "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": "." + } + } + } +} diff --git a/i18n/langZH.js b/i18n/langZH.js deleted file mode 100644 index 5b2a4d94dc..0000000000 --- a/i18n/langZH.js +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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. - */ - -(function(root, factory) { - if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define(['exports', 'echarts'], factory); - } else if ( - typeof exports === 'object' && - typeof exports.nodeName !== 'string' - ) { - // CommonJS - factory(exports, require('echarts')); - } else { - // Browser globals - factory({}, root.echarts); - } -})(this, function(exports, echarts) { - let lang = { - - legend: { - selector: { - all: '全选', - inverse: '反选' - } - }, - toolbox: { - brush: { - title: { - rect: '矩形选择', - polygon: '圈选', - lineX: '横向选择', - lineY: '纵向选择', - keep: '保持选择', - clear: '清除选择' - } - }, - dataView: { - title: '数据视图', - lang: ['数据视图', '关闭', '刷新'] - }, - dataZoom: { - title: { - zoom: '区域缩放', - back: '区域缩放还原' - } - }, - magicType: { - title: { - line: '切换为折线图', - bar: '切换为柱状图', - stack: '切换为堆叠', - tiled: '切换为平铺' - } - }, - restore: { - title: '还原' - }, - saveAsImage: { - title: '保存为图片', - lang: ['右键另存为图片'] - } - }, - series: { - typeNames: { - pie: '饼图', - bar: '柱状图', - line: '折线图', - scatter: '散点图', - effectScatter: '涟漪散点图', - radar: '雷达图', - tree: '树图', - treemap: '矩形树图', - boxplot: '箱型图', - candlestick: 'K线图', - k: 'K线图', - heatmap: '热力图', - map: '地图', - parallel: '平行坐标图', - lines: '线图', - graph: '关系图', - sankey: '桑基图', - funnel: '漏斗图', - gauge: '仪表盘图', - pictorialBar: '象形柱图', - themeRiver: '主题河流图', - sunburst: '旭日图' - } - }, - aria: { - general: { - withTitle: '这是一个关于“{title}”的图表。', - withoutTitle: '这是一个图表,' - }, - series: { - single: { - prefix: '', - withName: '图表类型是{seriesType},表示{seriesName}。', - withoutName: '图表类型是{seriesType}。' - }, - multiple: { - prefix: '它由{seriesCount}个图表系列组成。', - withName: '第{seriesId}个系列是一个表示{seriesName}的{seriesType},', - withoutName: '第{seriesId}个系列是一个{seriesType},', - separator: { - middle: ';', - end: '。' - } - } - }, - data: { - allData: '其数据是——', - partialData: '其中,前{displayCnt}项是——', - withName: '{name}的数据是{value}', - withoutName: '{value}', - separator: { - middle: ',', - end: '' - } - } - } - }; - - echarts.registerLocale('ZH', lang); -}); diff --git a/i18n/langZH.json b/i18n/langZH.json new file mode 100644 index 0000000000..5c64933e5e --- /dev/null +++ b/i18n/langZH.json @@ -0,0 +1,109 @@ +{ + "legend": { + "selector": { + "all": "全选", + "inverse": "反选" + } + }, + "toolbox": { + "brush": { + "title": { + "rect": "矩形选择", + "polygon": "圈选", + "lineX": "横向选择", + "lineY": "纵向选择", + "keep": "保持选择", + "clear": "清除选择" + } + }, + "dataView": { + "title": "数据视图", + "lang": [ + "数据视图", + "关闭", + "刷新" + ] + }, + "dataZoom": { + "title": { + "zoom": "区域缩放", + "back": "区域缩放还原" + } + }, + "magicType": { + "title": { + "line": "切换为折线图", + "bar": "切换为柱状图", + "stack": "切换为堆叠", + "tiled": "切换为平铺" + } + }, + "restore": { + "title": "还原" + }, + "saveAsImage": { + "title": "保存为图片", + "lang": [ + "右键另存为图片" + ] + } + }, + "series": { + "typeNames": { + "pie": "饼图", + "bar": "柱状图", + "line": "折线图", + "scatter": "散点图", + "effectScatter": "涟漪散点图", + "radar": "雷达图", + "tree": "树图", + "treemap": "矩形树图", + "boxplot": "箱型图", + "candlestick": "K线图", + "k": "K线图", + "heatmap": "热力图", + "map": "地图", + "parallel": "平行坐标图", + "lines": "线图", + "graph": "关系图", + "sankey": "桑基图", + "funnel": "漏斗图", + "gauge": "仪表盘图", + "pictorialBar": "象形柱图", + "themeRiver": "主题河流图", + "sunburst": "旭日图" + } + }, + "aria": { + "general": { + "withTitle": "这是一个关于“{title}”的图表。", + "withoutTitle": "这是一个图表," + }, + "series": { + "single": { + "prefix": "", + "withName": "图表类型是{seriesType},表示{seriesName}。", + "withoutName": "图表类型是{seriesType}。" + }, + "multiple": { + "prefix": "它由{seriesCount}个图表系列组成。", + "withName": "第{seriesId}个系列是一个表示{seriesName}的{seriesType},", + "withoutName": "第{seriesId}个系列是一个{seriesType},", + "separator": { + "middle": ";", + "end": "。" + } + } + }, + "data": { + "allData": "其数据是——", + "partialData": "其中,前{displayCnt}项是——", + "withName": "{name}的数据是{value}", + "withoutName": "{value}", + "separator": { + "middle": ",", + "end": "" + } + } + } +} diff --git a/package.json b/package.json index 18b43e4999..af19970555 100644 --- a/package.json +++ b/package.json @@ -13,11 +13,12 @@ "url": "https://github.com/apache/incubator-echarts.git" }, "scripts": { + "buildi18n": "node build/build-i18n.js", "prepublish": "node build/build.js --prepublish", "build": "node build/build.js", "build:full": "node build/build.js --clean", "watch": "node build/build.js --watch", - "dev:fast": "node build/dev-fast.js", + "dev:fast": "node build/build-i18n.js && node build/dev-fast.js", "release": "node build/build.js --release", "help": "node build/build.js --help", "test:visual": "node test/runTest/server.js", diff --git a/src/echarts.ts b/src/echarts.ts index 73c883b7e4..e242e88470 100644 --- a/src/echarts.ts +++ b/src/echarts.ts @@ -92,6 +92,9 @@ import { getVisualFromData, getItemVisualFromData } from './visual/helper'; import LabelManager from './label/LabelManager'; import { deprecateLog } from './util/log'; import { handleLegacySelectEvents } from './legacy/dataSelectAction'; +// default import ZH and EN lang +import langEN from "../i18n/langEN"; +import langZH from "../i18n/langZH"; // At least canvas renderer. import 'zrender/src/canvas/canvas'; @@ -312,8 +315,8 @@ class ECharts extends Eventful { dom: HTMLElement, // Theme name or themeOption. theme?: string | ThemeOption, - locale?: string | LocaleOption, opts?: { + locale?: string | LocaleOption, renderer?: RendererType, devicePixelRatio?: number, width?: number, @@ -352,8 +355,13 @@ class ECharts extends Eventful { theme && backwardCompat(theme as ECUnitOption, true); this._theme = theme; - this._locale = typeof locale === 'string' ? localeStorage[locale || 'ZH'] : zrUtil.clone(locale); - console.log(this._locale); + + const {locale = 'ZH'} = opts; + // set default lang package + localeStorage['ZH'] = localeStorage['ZH'] || langZH; + localeStorage['EN'] = localeStorage['EN'] || langEN; + this._locale = typeof locale === 'string' ? localeStorage[locale] : zrUtil.clone(locale); + console.log(this._locale) this._coordSysMgr = new CoordinateSystemManager(); @@ -2329,12 +2337,12 @@ const DOM_ATTRIBUTE_KEY = '_echarts_instance_'; export function init( dom: HTMLElement, theme?: string | object, - locale?: string | object, opts?: { renderer?: RendererType, devicePixelRatio?: number, width?: number, - height?: number + height?: number, + locale?: string | object, } ): ECharts { if (__DEV__) { @@ -2376,7 +2384,7 @@ export function init( } } - const chart = new ECharts(dom, theme, locale, opts); + const chart = new ECharts(dom, theme, opts); chart.id = 'ec_' + idBase++; instances[chart.id] = chart; diff --git a/src/model/Global.ts b/src/model/Global.ts index d9109d0236..1557d201df 100644 --- a/src/model/Global.ts +++ b/src/model/Global.ts @@ -128,7 +128,6 @@ class GlobalModel extends Model { theme = theme || {}; this.option = null; // Mark as not initialized. this._theme = new Model(theme); - console.log('init', locale) this._locale = locale; this._optionManager = optionManager; } @@ -428,7 +427,7 @@ class GlobalModel extends Model { } getWithLocale(localePosition: Array, optionsPosition?: Array, localeHandlerFn?: (text: string) => string): any { - console.log(optionsPosition, localePosition); + // console.log(optionsPosition, localePosition); const locale = this.getLocale() let localeText: string | any; localePosition.map(t => { @@ -438,7 +437,7 @@ class GlobalModel extends Model { if(localeHandlerFn) { localeText = localeHandlerFn(localeText); } - console.log(localeText); + // console.log(localeText); return localeText; } diff --git a/test/lang.html b/test/lang.html index a498ab3ccc..231355fdcc 100644 --- a/test/lang.html +++ b/test/lang.html @@ -39,11 +39,13 @@ } +
+ + From 45c92c695a5377bcb046fb422afd50e910513f68 Mon Sep 17 00:00:00 2001 From: zakwu <123537200@qq.com> Date: Wed, 29 Jul 2020 09:59:06 +0800 Subject: [PATCH 03/14] feat(i18n): code review --- i18n/langES.json | 51 +++++++++++++++++++++++++ i18n/langES.ts | 68 --------------------------------- i18n/langFI.json | 51 +++++++++++++++++++++++++ i18n/langFI.ts | 68 --------------------------------- i18n/langTH.json | 51 +++++++++++++++++++++++++ i18n/langTH.ts | 68 --------------------------------- test/lang.html | 99 ++++++++++++++++-------------------------------- 7 files changed, 186 insertions(+), 270 deletions(-) create mode 100644 i18n/langES.json delete mode 100644 i18n/langES.ts create mode 100644 i18n/langFI.json delete mode 100644 i18n/langFI.ts create mode 100644 i18n/langTH.json delete mode 100644 i18n/langTH.ts diff --git a/i18n/langES.json b/i18n/langES.json new file mode 100644 index 0000000000..055e7d2c7f --- /dev/null +++ b/i18n/langES.json @@ -0,0 +1,51 @@ +{ + "legend": { + "selector": { + "all": "Todas", + "inverse": "Inversa" + } + }, + "toolbox": { + "brush": { + "title": { + "rect": "Selección de cuadro", + "polygon": "Selección de lazo", + "lineX": "Seleccionar horizontalmente", + "lineY": "Seleccionar verticalmente", + "keep": "Mantener selección", + "clear": "Despejar selecciones" + } + }, + "dataView": { + "title": "Ver datos", + "lang": [ + "Ver datos", + "Cerrar", + "Actualizar" + ] + }, + "dataZoom": { + "title": { + "zoom": "Zoom", + "back": "Restablecer zoom" + } + }, + "magicType": { + "title": { + "line": "Cambiar a gráfico de líneas", + "bar": "Cambiar a gráfico de barras", + "stack": "Pila", + "tiled": "Teja" + } + }, + "restore": { + "title": "Restaurar" + }, + "saveAsImage": { + "title": "Guardar como imagen", + "lang": [ + "Clic derecho para guardar imagen" + ] + } + } +} diff --git a/i18n/langES.ts b/i18n/langES.ts deleted file mode 100644 index 2fba545c8a..0000000000 --- a/i18n/langES.ts +++ /dev/null @@ -1,68 +0,0 @@ -/* -* 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. -*/ - -/** - * Language: Spanish - */ - -export default { - legend: { - selector: { - all: 'Todas', - inverse: 'Inversa' - } - }, - toolbox: { - brush: { - title: { - rect: 'Selección de cuadro', - polygon: 'Selección de lazo', - lineX: 'Seleccionar horizontalmente', - lineY: 'Seleccionar verticalmente', - keep: 'Mantener selección', - clear: 'Despejar selecciones' - } - }, - dataView: { - title: 'Ver datos', - lang: ['Ver datos', 'Cerrar', 'Actualizar'] - }, - dataZoom: { - title: { - zoom: 'Zoom', - back: 'Restablecer zoom' - } - }, - magicType: { - title: { - line: 'Cambiar a gráfico de líneas', - bar: 'Cambiar a gráfico de barras', - stack: 'Pila', - tiled: 'Teja' - } - }, - restore: { - title: 'Restaurar' - }, - saveAsImage: { - title: 'Guardar como imagen', - lang: ['Clic derecho para guardar imagen'] - } - } -}; diff --git a/i18n/langFI.json b/i18n/langFI.json new file mode 100644 index 0000000000..1fe6894041 --- /dev/null +++ b/i18n/langFI.json @@ -0,0 +1,51 @@ +{ + "legend": { + "selector": { + "all": "Kaikki", + "inverse": "Käänteinen" + } + }, + "toolbox": { + "brush": { + "title": { + "rect": "Laatikko valinta", + "polygon": "Lasso valinta", + "lineX": "Vaakataso valinta", + "lineY": "Pysty valinta", + "keep": "Pidä valinta", + "clear": "Poista valinta" + } + }, + "dataView": { + "title": "Data näkymä", + "lang": [ + "Data näkymä", + "Sulje", + "Päivitä" + ] + }, + "dataZoom": { + "title": { + "zoom": "Zoomaa", + "back": "Zoomin nollaus" + } + }, + "magicType": { + "title": { + "line": "Vaihda Viivakaavioon", + "bar": "Vaihda palkkikaavioon", + "stack": "Pinoa", + "tiled": "Erottele" + } + }, + "restore": { + "title": "Palauta" + }, + "saveAsImage": { + "title": "Tallenna kuvana", + "lang": [ + "Paina oikeaa hiirennappia tallentaaksesi kuva" + ] + } + } +} diff --git a/i18n/langFI.ts b/i18n/langFI.ts deleted file mode 100644 index bdeffe48ec..0000000000 --- a/i18n/langFI.ts +++ /dev/null @@ -1,68 +0,0 @@ -/* -* 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. -*/ - -/** - * Language: Finnish - */ - -export default { - legend: { - selector: { - all: 'Kaikki', - inverse: 'Käänteinen' - } - }, - toolbox: { - brush: { - title: { - rect: 'Laatikko valinta', - polygon: 'Lasso valinta', - lineX: 'Vaakataso valinta', - lineY: 'Pysty valinta', - keep: 'Pidä valinta', - clear: 'Poista valinta' - } - }, - dataView: { - title: 'Data näkymä', - lang: ['Data näkymä', 'Sulje', 'Päivitä'] - }, - dataZoom: { - title: { - zoom: 'Zoomaa', - back: 'Zoomin nollaus' - } - }, - magicType: { - title: { - line: 'Vaihda Viivakaavioon', - bar: 'Vaihda palkkikaavioon', - stack: 'Pinoa', - tiled: 'Erottele' - } - }, - restore: { - title: 'Palauta' - }, - saveAsImage: { - title: 'Tallenna kuvana', - lang: ['Paina oikeaa hiirennappia tallentaaksesi kuva'] - } - } -}; diff --git a/i18n/langTH.json b/i18n/langTH.json new file mode 100644 index 0000000000..163797150b --- /dev/null +++ b/i18n/langTH.json @@ -0,0 +1,51 @@ +{ + "legend": { + "selector": { + "all": "ทั้งหมด", + "inverse": "ผกผัน" + } + }, + "toolbox": { + "brush": { + "title": { + "rect": "ตัวเลือกแบบกล่อง", + "polygon": "ตัวเลือกแบบบ่วงบาศ", + "lineX": "ตัวเลือกแบบแนวนอน", + "lineY": "ตัวเลือกแบบแนวตั้ง", + "keep": "บันทึกตัวเลือก", + "clear": "ล้างตัวเลือก" + } + }, + "dataView": { + "title": "มุมมองข้อมูล", + "lang": [ + "มุมมองข้อมูล", + "ปิด", + "รีเฟรช" + ] + }, + "dataZoom": { + "title": { + "zoom": "ซูม", + "back": "ตั้งซูมใหม่" + } + }, + "magicType": { + "title": { + "line": "สวิตซ์แบบแผนภาพเส้น", + "bar": "สวิตซ์แบบแผนภาพแท่ง", + "stack": "กองไว้", + "tiled": "แยกไว้" + } + }, + "restore": { + "title": "ตั้งค่าใหม่" + }, + "saveAsImage": { + "title": "บันทึกไปยังรูปภาพ", + "lang": [ + "คลิกขวาเพื่อบันทึกรูปภาพ" + ] + } + } +} diff --git a/i18n/langTH.ts b/i18n/langTH.ts deleted file mode 100644 index 0ae102d15f..0000000000 --- a/i18n/langTH.ts +++ /dev/null @@ -1,68 +0,0 @@ -/* -* 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. -*/ - -/** - * Language: Thai - */ - -export default { - legend: { - selector: { - all: 'ทั้งหมด', - inverse: 'ผกผัน' - } - }, - toolbox: { - brush: { - title: { - rect: 'ตัวเลือกแบบกล่อง', - polygon: 'ตัวเลือกแบบบ่วงบาศ', - lineX: 'ตัวเลือกแบบแนวนอน', - lineY: 'ตัวเลือกแบบแนวตั้ง', - keep: 'บันทึกตัวเลือก', - clear: 'ล้างตัวเลือก' - } - }, - dataView: { - title: 'มุมมองข้อมูล', - lang: ['มุมมองข้อมูล', 'ปิด', 'รีเฟรช'] - }, - dataZoom: { - title: { - zoom: 'ซูม', - back: 'ตั้งซูมใหม่' - } - }, - magicType: { - title: { - line: 'สวิตซ์แบบแผนภาพเส้น', - bar: 'สวิตซ์แบบแผนภาพแท่ง', - stack: 'กองไว้', - tiled: 'แยกไว้' - } - }, - restore: { - title: 'ตั้งค่าใหม่' - }, - saveAsImage: { - title: 'บันทึกไปยังรูปภาพ', - lang: ['คลิกขวาเพื่อบันทึกรูปภาพ'] - } - } -}; diff --git a/test/lang.html b/test/lang.html index 231355fdcc..35a7bd0069 100644 --- a/test/lang.html +++ b/test/lang.html @@ -44,64 +44,52 @@
+ @@ -109,31 +97,10 @@ // register lang require(['echarts', 'i18n/langEN-obj'], function (echarts, {lang}) { echarts.registerLocale('EN', lang); - var option = { - xAxis: {}, - yAxis: {}, - series: { - type: 'line', - data: [[11, 22], [33, 44]] - }, - toolbox: { - show: true, - feature: { - restore: {}, - saveAsImage: {}, - dataZoom: {}, - dataView: {} - }, - orient: 'vertical', - right: 5 - }, - animation: false - }; - var chart = echarts.init(document.getElementById('main1'), null, { locale: 'EN' }); - chart.setOption(option); + chart.setOption(window.option); }); From 25181b1d4d6f95dae84e948a97590e1f0c3ec8f1 Mon Sep 17 00:00:00 2001 From: zakwu <123537200@qq.com> Date: Wed, 29 Jul 2020 10:05:32 +0800 Subject: [PATCH 04/14] feat(i18n): code review --- test/lang.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/lang.html b/test/lang.html index 35a7bd0069..0d27cc600d 100644 --- a/test/lang.html +++ b/test/lang.html @@ -42,6 +42,7 @@
+
+ + From b59e1f7a01730f1cf801f4560e191955700f5568 Mon Sep 17 00:00:00 2001 From: zakwu <123537200@qq.com> Date: Wed, 29 Jul 2020 12:40:08 +0800 Subject: [PATCH 05/14] feat(i18n): draft commit for discuss --- build/build-i18n.js | 4 ++-- src/echarts.ts | 6 ++---- {i18n => src/i18n}/langEN.json | 0 {i18n => src/i18n}/langES.json | 0 {i18n => src/i18n}/langFI.json | 0 {i18n => src/i18n}/langTH.json | 0 {i18n => src/i18n}/langZH.json | 0 src/model/Global.ts | 15 +++++++-------- src/visual/aria.ts | 5 +++-- test/lang.html | 6 +++--- 10 files changed, 17 insertions(+), 19 deletions(-) rename {i18n => src/i18n}/langEN.json (100%) rename {i18n => src/i18n}/langES.json (100%) rename {i18n => src/i18n}/langFI.json (100%) rename {i18n => src/i18n}/langTH.json (100%) rename {i18n => src/i18n}/langZH.json (100%) diff --git a/build/build-i18n.js b/build/build-i18n.js index 7a768ea72e..a09af77c6b 100644 --- a/build/build-i18n.js +++ b/build/build-i18n.js @@ -1,6 +1,6 @@ const fs = require('fs'); -const outFilePath = './i18n'; +const outFilePath = './src/i18n'; const umdWrapperHead = ` (function(root, factory) { if (typeof define === 'function' && define.amd) { @@ -41,7 +41,7 @@ const umdWrapperTail = ` });`; async function buildI18nWrap() { - const targetDir = './i18n'; + const targetDir = './src/i18n'; const files = fs.readdirSync(targetDir); files.forEach(t => { if(!t.startsWith('lang') || !t.endsWith('json')) return; diff --git a/src/echarts.ts b/src/echarts.ts index e242e88470..b35f2ef84a 100644 --- a/src/echarts.ts +++ b/src/echarts.ts @@ -93,8 +93,8 @@ import LabelManager from './label/LabelManager'; import { deprecateLog } from './util/log'; import { handleLegacySelectEvents } from './legacy/dataSelectAction'; // default import ZH and EN lang -import langEN from "../i18n/langEN"; -import langZH from "../i18n/langZH"; +import langEN from "./i18n/langEN"; +import langZH from "./i18n/langZH"; // At least canvas renderer. import 'zrender/src/canvas/canvas'; @@ -361,7 +361,6 @@ class ECharts extends Eventful { localeStorage['ZH'] = localeStorage['ZH'] || langZH; localeStorage['EN'] = localeStorage['EN'] || langEN; this._locale = typeof locale === 'string' ? localeStorage[locale] : zrUtil.clone(locale); - console.log(this._locale) this._coordSysMgr = new CoordinateSystemManager(); @@ -2477,7 +2476,6 @@ export function registerTheme(name: string, theme: ThemeOption): void { export function registerLocale(name: string, locale: LocaleOption): void { localeStorage[name] = locale; - console.log('localeStorage', localeStorage); } /** diff --git a/i18n/langEN.json b/src/i18n/langEN.json similarity index 100% rename from i18n/langEN.json rename to src/i18n/langEN.json diff --git a/i18n/langES.json b/src/i18n/langES.json similarity index 100% rename from i18n/langES.json rename to src/i18n/langES.json diff --git a/i18n/langFI.json b/src/i18n/langFI.json similarity index 100% rename from i18n/langFI.json rename to src/i18n/langFI.json diff --git a/i18n/langTH.json b/src/i18n/langTH.json similarity index 100% rename from i18n/langTH.json rename to src/i18n/langTH.json diff --git a/i18n/langZH.json b/src/i18n/langZH.json similarity index 100% rename from i18n/langZH.json rename to src/i18n/langZH.json diff --git a/src/model/Global.ts b/src/model/Global.ts index 1557d201df..1d3b1b5b71 100644 --- a/src/model/Global.ts +++ b/src/model/Global.ts @@ -58,7 +58,6 @@ import { import OptionManager from './OptionManager'; import Scheduler from '../stream/Scheduler'; import { concatInternalOptions } from './internalComponentCreator'; -import {Dictionary} from "zrender/src/core/types"; export interface GlobalModelSetOptionOpts { replaceMerge: ComponentMainType | ComponentMainType[]; @@ -426,18 +425,18 @@ class GlobalModel extends Model { return this._locale; } - getWithLocale(localePosition: Array, optionsPosition?: Array, localeHandlerFn?: (text: string) => string): any { - // console.log(optionsPosition, localePosition); - const locale = this.getLocale() + getWithLocale(localePosition: Array, + optionsPosition?: Array, + localeHandlerFn?: (text: string) => string): any { + const locale = this.getLocale(); let localeText: string | any; localePosition.map(t => { localeText = localeText ? localeText[t] : locale[t]; - }) + }); - if(localeHandlerFn) { - localeText = localeHandlerFn(localeText); + if (localeHandlerFn) { + localeText = localeHandlerFn(localeText); } - // console.log(localeText); return localeText; } diff --git a/src/visual/aria.ts b/src/visual/aria.ts index aa75400ef6..7ced6697f0 100644 --- a/src/visual/aria.ts +++ b/src/visual/aria.ts @@ -20,8 +20,9 @@ // @ts-nocheck import * as zrUtil from 'zrender/src/core/util'; -import lang from '../lang'; -import { retrieveRawValue } from '../data/helper/dataProvider'; +import { retrieveRawValue } + +from '../data/helper/dataProvider'; export default function (dom, ecModel) { const ariaModel = ecModel.getModel('aria'); diff --git a/test/lang.html b/test/lang.html index 0d27cc600d..211e8a21bc 100644 --- a/test/lang.html +++ b/test/lang.html @@ -86,7 +86,7 @@ From 7630eb82ff65dcdb35fd84b4d8c40eb7fe4f4944 Mon Sep 17 00:00:00 2001 From: zakwu <123537200@qq.com> Date: Wed, 29 Jul 2020 18:27:50 +0800 Subject: [PATCH 08/14] feat(i18n): get default lang by use browser lang and html.lang --- src/echarts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/echarts.ts b/src/echarts.ts index e8e4733bb1..6b7b4c5118 100644 --- a/src/echarts.ts +++ b/src/echarts.ts @@ -358,7 +358,7 @@ class ECharts extends Eventful { const browserLang: string = !env.browser ? 'ZH' : (() => { const langStr = (document.documentElement.lang || navigator.language || (navigator as any).browserLanguage).toUpperCase(); - return langStr.indexOf('ZH') > -1 ? 'ZH' : 'EN'; + return langStr.indexOf('EN') > -1 ? 'EN' : 'ZH'; })(); const {locale = browserLang} = opts; // set default lang package From 4289f0d0ecc58668c06b3d258fd3b854332c7dc0 Mon Sep 17 00:00:00 2001 From: zakwu <123537200@qq.com> Date: Thu, 30 Jul 2020 09:28:14 +0800 Subject: [PATCH 09/14] feat(i18n): fix some review suggestion --- build/build-i18n.js | 3 +-- package.json | 2 +- src/echarts.ts | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/build/build-i18n.js b/build/build-i18n.js index a09af77c6b..a65055ca36 100644 --- a/build/build-i18n.js +++ b/build/build-i18n.js @@ -46,7 +46,6 @@ async function buildI18nWrap() { files.forEach(t => { if(!t.startsWith('lang') || !t.endsWith('json')) return; const fileName = t.substring(0, t.length - 5); - console.log(fileName + ' is building...'); const type = t.substr(-7, 2); const echartsRegister = ` echarts.registerLocale('${type}', lang); @@ -58,8 +57,8 @@ async function buildI18nWrap() { 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(outFilePath + '/' + fileName + '.ts', 'export default ' + code, 'utf-8'); - console.log(fileName + ' done'); }) + console.log('i18n build completed'); } buildI18nWrap(); diff --git a/package.json b/package.json index af19970555..5ceabe5528 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,9 @@ "url": "https://github.com/apache/incubator-echarts.git" }, "scripts": { - "buildi18n": "node build/build-i18n.js", "prepublish": "node build/build.js --prepublish", "build": "node build/build.js", + "build:i18n": "node build/build-i18n.js", "build:full": "node build/build.js --clean", "watch": "node build/build.js --watch", "dev:fast": "node build/build-i18n.js && node build/dev-fast.js", diff --git a/src/echarts.ts b/src/echarts.ts index 6b7b4c5118..fdd571b5d2 100644 --- a/src/echarts.ts +++ b/src/echarts.ts @@ -356,7 +356,7 @@ class ECharts extends Eventful { this._theme = theme; - const browserLang: string = !env.browser ? 'ZH' : (() => { + const browserLang: string = !env.domSupported ? 'ZH' : (() => { const langStr = (document.documentElement.lang || navigator.language || (navigator as any).browserLanguage).toUpperCase(); return langStr.indexOf('EN') > -1 ? 'EN' : 'ZH'; })(); @@ -2345,7 +2345,7 @@ export function init( devicePixelRatio?: number, width?: number, height?: number, - locale?: string | object, + locale?: string | object } ): ECharts { if (__DEV__) { From aa2d448d092faa75b7ec98a3799e1ec08fe2bf32 Mon Sep 17 00:00:00 2001 From: zakwu <123537200@qq.com> Date: Thu, 30 Jul 2020 11:03:09 +0800 Subject: [PATCH 10/14] feat(i18n): change build-i18n for package --- build/build-i18n.js | 4 +- i18n/langEN-obj.js | 129 ++++++++++++++++++++++++++++++++++++++++++++ i18n/langEN.js | 129 ++++++++++++++++++++++++++++++++++++++++++++ i18n/langES-obj.js | 71 ++++++++++++++++++++++++ i18n/langES.js | 71 ++++++++++++++++++++++++ i18n/langFI-obj.js | 71 ++++++++++++++++++++++++ i18n/langFI.js | 71 ++++++++++++++++++++++++ i18n/langTH-obj.js | 71 ++++++++++++++++++++++++ i18n/langTH.js | 71 ++++++++++++++++++++++++ i18n/langZH-obj.js | 129 ++++++++++++++++++++++++++++++++++++++++++++ i18n/langZH.js | 129 ++++++++++++++++++++++++++++++++++++++++++++ test/lang.html | 6 +-- 12 files changed, 947 insertions(+), 5 deletions(-) create mode 100644 i18n/langEN-obj.js create mode 100644 i18n/langEN.js create mode 100644 i18n/langES-obj.js create mode 100644 i18n/langES.js create mode 100644 i18n/langFI-obj.js create mode 100644 i18n/langFI.js create mode 100644 i18n/langTH-obj.js create mode 100644 i18n/langTH.js create mode 100644 i18n/langZH-obj.js create mode 100644 i18n/langZH.js diff --git a/build/build-i18n.js b/build/build-i18n.js index a65055ca36..f0054c607d 100644 --- a/build/build-i18n.js +++ b/build/build-i18n.js @@ -1,6 +1,6 @@ const fs = require('fs'); -const outFilePath = './src/i18n'; +const outFilePath = './i18n'; const umdWrapperHead = ` (function(root, factory) { if (typeof define === 'function' && define.amd) { @@ -56,7 +56,7 @@ async function buildI18nWrap() { 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(outFilePath + '/' + fileName + '.ts', 'export default ' + code, 'utf-8'); + fs.writeFileSync(targetDir + '/' + fileName + '.ts', 'export default ' + code, 'utf-8'); }) console.log('i18n build completed'); } diff --git a/i18n/langEN-obj.js b/i18n/langEN-obj.js new file mode 100644 index 0000000000..2198d57c39 --- /dev/null +++ b/i18n/langEN-obj.js @@ -0,0 +1,129 @@ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports); + } else { + // Browser globals + factory({}); + } +})(this, function(exports) { +var lang ={ + "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" + } + }, + "dataView": { + "title": "Data View", + "lang": [ + "Data View", + "Close", + "Refresh" + ] + }, + "dataZoom": { + "title": { + "zoom": "Zoom", + "back": "Zoom Reset" + } + }, + "magicType": { + "title": { + "line": "Switch to Line Chart", + "bar": "Switch to Bar Chart", + "stack": "Stack", + "tiled": "Tile" + } + }, + "restore": { + "title": "Restore" + }, + "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" + } + }, + "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}." + }, + "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": "." + } + } + } +} + + exports.lang = lang; + +}); \ No newline at end of file diff --git a/i18n/langEN.js b/i18n/langEN.js new file mode 100644 index 0000000000..c40ea9bca2 --- /dev/null +++ b/i18n/langEN.js @@ -0,0 +1,129 @@ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports', 'echarts'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports, require('echarts')); + } else { + // Browser globals + factory({}, root.echarts); + } +})(this, function(exports, echarts) { +var lang ={ + "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" + } + }, + "dataView": { + "title": "Data View", + "lang": [ + "Data View", + "Close", + "Refresh" + ] + }, + "dataZoom": { + "title": { + "zoom": "Zoom", + "back": "Zoom Reset" + } + }, + "magicType": { + "title": { + "line": "Switch to Line Chart", + "bar": "Switch to Bar Chart", + "stack": "Stack", + "tiled": "Tile" + } + }, + "restore": { + "title": "Restore" + }, + "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" + } + }, + "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}." + }, + "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": "." + } + } + } +} + + echarts.registerLocale('EN', lang); + +}); \ No newline at end of file diff --git a/i18n/langES-obj.js b/i18n/langES-obj.js new file mode 100644 index 0000000000..2e1288b0c7 --- /dev/null +++ b/i18n/langES-obj.js @@ -0,0 +1,71 @@ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports); + } else { + // Browser globals + factory({}); + } +})(this, function(exports) { +var lang ={ + "legend": { + "selector": { + "all": "Todas", + "inverse": "Inversa" + } + }, + "toolbox": { + "brush": { + "title": { + "rect": "Selección de cuadro", + "polygon": "Selección de lazo", + "lineX": "Seleccionar horizontalmente", + "lineY": "Seleccionar verticalmente", + "keep": "Mantener selección", + "clear": "Despejar selecciones" + } + }, + "dataView": { + "title": "Ver datos", + "lang": [ + "Ver datos", + "Cerrar", + "Actualizar" + ] + }, + "dataZoom": { + "title": { + "zoom": "Zoom", + "back": "Restablecer zoom" + } + }, + "magicType": { + "title": { + "line": "Cambiar a gráfico de líneas", + "bar": "Cambiar a gráfico de barras", + "stack": "Pila", + "tiled": "Teja" + } + }, + "restore": { + "title": "Restaurar" + }, + "saveAsImage": { + "title": "Guardar como imagen", + "lang": [ + "Clic derecho para guardar imagen" + ] + } + } +} + + exports.lang = lang; + +}); \ No newline at end of file diff --git a/i18n/langES.js b/i18n/langES.js new file mode 100644 index 0000000000..236716b5f8 --- /dev/null +++ b/i18n/langES.js @@ -0,0 +1,71 @@ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports', 'echarts'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports, require('echarts')); + } else { + // Browser globals + factory({}, root.echarts); + } +})(this, function(exports, echarts) { +var lang ={ + "legend": { + "selector": { + "all": "Todas", + "inverse": "Inversa" + } + }, + "toolbox": { + "brush": { + "title": { + "rect": "Selección de cuadro", + "polygon": "Selección de lazo", + "lineX": "Seleccionar horizontalmente", + "lineY": "Seleccionar verticalmente", + "keep": "Mantener selección", + "clear": "Despejar selecciones" + } + }, + "dataView": { + "title": "Ver datos", + "lang": [ + "Ver datos", + "Cerrar", + "Actualizar" + ] + }, + "dataZoom": { + "title": { + "zoom": "Zoom", + "back": "Restablecer zoom" + } + }, + "magicType": { + "title": { + "line": "Cambiar a gráfico de líneas", + "bar": "Cambiar a gráfico de barras", + "stack": "Pila", + "tiled": "Teja" + } + }, + "restore": { + "title": "Restaurar" + }, + "saveAsImage": { + "title": "Guardar como imagen", + "lang": [ + "Clic derecho para guardar imagen" + ] + } + } +} + + echarts.registerLocale('ES', lang); + +}); \ No newline at end of file diff --git a/i18n/langFI-obj.js b/i18n/langFI-obj.js new file mode 100644 index 0000000000..637c10be1b --- /dev/null +++ b/i18n/langFI-obj.js @@ -0,0 +1,71 @@ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports); + } else { + // Browser globals + factory({}); + } +})(this, function(exports) { +var lang ={ + "legend": { + "selector": { + "all": "Kaikki", + "inverse": "Käänteinen" + } + }, + "toolbox": { + "brush": { + "title": { + "rect": "Laatikko valinta", + "polygon": "Lasso valinta", + "lineX": "Vaakataso valinta", + "lineY": "Pysty valinta", + "keep": "Pidä valinta", + "clear": "Poista valinta" + } + }, + "dataView": { + "title": "Data näkymä", + "lang": [ + "Data näkymä", + "Sulje", + "Päivitä" + ] + }, + "dataZoom": { + "title": { + "zoom": "Zoomaa", + "back": "Zoomin nollaus" + } + }, + "magicType": { + "title": { + "line": "Vaihda Viivakaavioon", + "bar": "Vaihda palkkikaavioon", + "stack": "Pinoa", + "tiled": "Erottele" + } + }, + "restore": { + "title": "Palauta" + }, + "saveAsImage": { + "title": "Tallenna kuvana", + "lang": [ + "Paina oikeaa hiirennappia tallentaaksesi kuva" + ] + } + } +} + + exports.lang = lang; + +}); \ No newline at end of file diff --git a/i18n/langFI.js b/i18n/langFI.js new file mode 100644 index 0000000000..8ec5105650 --- /dev/null +++ b/i18n/langFI.js @@ -0,0 +1,71 @@ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports', 'echarts'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports, require('echarts')); + } else { + // Browser globals + factory({}, root.echarts); + } +})(this, function(exports, echarts) { +var lang ={ + "legend": { + "selector": { + "all": "Kaikki", + "inverse": "Käänteinen" + } + }, + "toolbox": { + "brush": { + "title": { + "rect": "Laatikko valinta", + "polygon": "Lasso valinta", + "lineX": "Vaakataso valinta", + "lineY": "Pysty valinta", + "keep": "Pidä valinta", + "clear": "Poista valinta" + } + }, + "dataView": { + "title": "Data näkymä", + "lang": [ + "Data näkymä", + "Sulje", + "Päivitä" + ] + }, + "dataZoom": { + "title": { + "zoom": "Zoomaa", + "back": "Zoomin nollaus" + } + }, + "magicType": { + "title": { + "line": "Vaihda Viivakaavioon", + "bar": "Vaihda palkkikaavioon", + "stack": "Pinoa", + "tiled": "Erottele" + } + }, + "restore": { + "title": "Palauta" + }, + "saveAsImage": { + "title": "Tallenna kuvana", + "lang": [ + "Paina oikeaa hiirennappia tallentaaksesi kuva" + ] + } + } +} + + echarts.registerLocale('FI', lang); + +}); \ No newline at end of file diff --git a/i18n/langTH-obj.js b/i18n/langTH-obj.js new file mode 100644 index 0000000000..e6f615061e --- /dev/null +++ b/i18n/langTH-obj.js @@ -0,0 +1,71 @@ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports); + } else { + // Browser globals + factory({}); + } +})(this, function(exports) { +var lang ={ + "legend": { + "selector": { + "all": "ทั้งหมด", + "inverse": "ผกผัน" + } + }, + "toolbox": { + "brush": { + "title": { + "rect": "ตัวเลือกแบบกล่อง", + "polygon": "ตัวเลือกแบบบ่วงบาศ", + "lineX": "ตัวเลือกแบบแนวนอน", + "lineY": "ตัวเลือกแบบแนวตั้ง", + "keep": "บันทึกตัวเลือก", + "clear": "ล้างตัวเลือก" + } + }, + "dataView": { + "title": "มุมมองข้อมูล", + "lang": [ + "มุมมองข้อมูล", + "ปิด", + "รีเฟรช" + ] + }, + "dataZoom": { + "title": { + "zoom": "ซูม", + "back": "ตั้งซูมใหม่" + } + }, + "magicType": { + "title": { + "line": "สวิตซ์แบบแผนภาพเส้น", + "bar": "สวิตซ์แบบแผนภาพแท่ง", + "stack": "กองไว้", + "tiled": "แยกไว้" + } + }, + "restore": { + "title": "ตั้งค่าใหม่" + }, + "saveAsImage": { + "title": "บันทึกไปยังรูปภาพ", + "lang": [ + "คลิกขวาเพื่อบันทึกรูปภาพ" + ] + } + } +} + + exports.lang = lang; + +}); \ No newline at end of file diff --git a/i18n/langTH.js b/i18n/langTH.js new file mode 100644 index 0000000000..c82a24e187 --- /dev/null +++ b/i18n/langTH.js @@ -0,0 +1,71 @@ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports', 'echarts'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports, require('echarts')); + } else { + // Browser globals + factory({}, root.echarts); + } +})(this, function(exports, echarts) { +var lang ={ + "legend": { + "selector": { + "all": "ทั้งหมด", + "inverse": "ผกผัน" + } + }, + "toolbox": { + "brush": { + "title": { + "rect": "ตัวเลือกแบบกล่อง", + "polygon": "ตัวเลือกแบบบ่วงบาศ", + "lineX": "ตัวเลือกแบบแนวนอน", + "lineY": "ตัวเลือกแบบแนวตั้ง", + "keep": "บันทึกตัวเลือก", + "clear": "ล้างตัวเลือก" + } + }, + "dataView": { + "title": "มุมมองข้อมูล", + "lang": [ + "มุมมองข้อมูล", + "ปิด", + "รีเฟรช" + ] + }, + "dataZoom": { + "title": { + "zoom": "ซูม", + "back": "ตั้งซูมใหม่" + } + }, + "magicType": { + "title": { + "line": "สวิตซ์แบบแผนภาพเส้น", + "bar": "สวิตซ์แบบแผนภาพแท่ง", + "stack": "กองไว้", + "tiled": "แยกไว้" + } + }, + "restore": { + "title": "ตั้งค่าใหม่" + }, + "saveAsImage": { + "title": "บันทึกไปยังรูปภาพ", + "lang": [ + "คลิกขวาเพื่อบันทึกรูปภาพ" + ] + } + } +} + + echarts.registerLocale('TH', lang); + +}); \ No newline at end of file diff --git a/i18n/langZH-obj.js b/i18n/langZH-obj.js new file mode 100644 index 0000000000..085a226286 --- /dev/null +++ b/i18n/langZH-obj.js @@ -0,0 +1,129 @@ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports); + } else { + // Browser globals + factory({}); + } +})(this, function(exports) { +var lang ={ + "legend": { + "selector": { + "all": "全选", + "inverse": "反选" + } + }, + "toolbox": { + "brush": { + "title": { + "rect": "矩形选择", + "polygon": "圈选", + "lineX": "横向选择", + "lineY": "纵向选择", + "keep": "保持选择", + "clear": "清除选择" + } + }, + "dataView": { + "title": "数据视图", + "lang": [ + "数据视图", + "关闭", + "刷新" + ] + }, + "dataZoom": { + "title": { + "zoom": "区域缩放", + "back": "区域缩放还原" + } + }, + "magicType": { + "title": { + "line": "切换为折线图", + "bar": "切换为柱状图", + "stack": "切换为堆叠", + "tiled": "切换为平铺" + } + }, + "restore": { + "title": "还原" + }, + "saveAsImage": { + "title": "保存为图片", + "lang": [ + "右键另存为图片" + ] + } + }, + "series": { + "typeNames": { + "pie": "饼图", + "bar": "柱状图", + "line": "折线图", + "scatter": "散点图", + "effectScatter": "涟漪散点图", + "radar": "雷达图", + "tree": "树图", + "treemap": "矩形树图", + "boxplot": "箱型图", + "candlestick": "K线图", + "k": "K线图", + "heatmap": "热力图", + "map": "地图", + "parallel": "平行坐标图", + "lines": "线图", + "graph": "关系图", + "sankey": "桑基图", + "funnel": "漏斗图", + "gauge": "仪表盘图", + "pictorialBar": "象形柱图", + "themeRiver": "主题河流图", + "sunburst": "旭日图" + } + }, + "aria": { + "general": { + "withTitle": "这是一个关于“{title}”的图表。", + "withoutTitle": "这是一个图表," + }, + "series": { + "single": { + "prefix": "", + "withName": "图表类型是{seriesType},表示{seriesName}。", + "withoutName": "图表类型是{seriesType}。" + }, + "multiple": { + "prefix": "它由{seriesCount}个图表系列组成。", + "withName": "第{seriesId}个系列是一个表示{seriesName}的{seriesType},", + "withoutName": "第{seriesId}个系列是一个{seriesType},", + "separator": { + "middle": ";", + "end": "。" + } + } + }, + "data": { + "allData": "其数据是——", + "partialData": "其中,前{displayCnt}项是——", + "withName": "{name}的数据是{value}", + "withoutName": "{value}", + "separator": { + "middle": ",", + "end": "" + } + } + } +} + + exports.lang = lang; + +}); \ No newline at end of file diff --git a/i18n/langZH.js b/i18n/langZH.js new file mode 100644 index 0000000000..7bd84b3372 --- /dev/null +++ b/i18n/langZH.js @@ -0,0 +1,129 @@ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports', 'echarts'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports, require('echarts')); + } else { + // Browser globals + factory({}, root.echarts); + } +})(this, function(exports, echarts) { +var lang ={ + "legend": { + "selector": { + "all": "全选", + "inverse": "反选" + } + }, + "toolbox": { + "brush": { + "title": { + "rect": "矩形选择", + "polygon": "圈选", + "lineX": "横向选择", + "lineY": "纵向选择", + "keep": "保持选择", + "clear": "清除选择" + } + }, + "dataView": { + "title": "数据视图", + "lang": [ + "数据视图", + "关闭", + "刷新" + ] + }, + "dataZoom": { + "title": { + "zoom": "区域缩放", + "back": "区域缩放还原" + } + }, + "magicType": { + "title": { + "line": "切换为折线图", + "bar": "切换为柱状图", + "stack": "切换为堆叠", + "tiled": "切换为平铺" + } + }, + "restore": { + "title": "还原" + }, + "saveAsImage": { + "title": "保存为图片", + "lang": [ + "右键另存为图片" + ] + } + }, + "series": { + "typeNames": { + "pie": "饼图", + "bar": "柱状图", + "line": "折线图", + "scatter": "散点图", + "effectScatter": "涟漪散点图", + "radar": "雷达图", + "tree": "树图", + "treemap": "矩形树图", + "boxplot": "箱型图", + "candlestick": "K线图", + "k": "K线图", + "heatmap": "热力图", + "map": "地图", + "parallel": "平行坐标图", + "lines": "线图", + "graph": "关系图", + "sankey": "桑基图", + "funnel": "漏斗图", + "gauge": "仪表盘图", + "pictorialBar": "象形柱图", + "themeRiver": "主题河流图", + "sunburst": "旭日图" + } + }, + "aria": { + "general": { + "withTitle": "这是一个关于“{title}”的图表。", + "withoutTitle": "这是一个图表," + }, + "series": { + "single": { + "prefix": "", + "withName": "图表类型是{seriesType},表示{seriesName}。", + "withoutName": "图表类型是{seriesType}。" + }, + "multiple": { + "prefix": "它由{seriesCount}个图表系列组成。", + "withName": "第{seriesId}个系列是一个表示{seriesName}的{seriesType},", + "withoutName": "第{seriesId}个系列是一个{seriesType},", + "separator": { + "middle": ";", + "end": "。" + } + } + }, + "data": { + "allData": "其数据是——", + "partialData": "其中,前{displayCnt}项是——", + "withName": "{name}的数据是{value}", + "withoutName": "{value}", + "separator": { + "middle": ",", + "end": "" + } + } + } +} + + echarts.registerLocale('ZH', lang); + +}); \ No newline at end of file diff --git a/test/lang.html b/test/lang.html index c1145a7648..1ae2ea3408 100644 --- a/test/lang.html +++ b/test/lang.html @@ -84,7 +84,7 @@ + +