Skip to content

Commit

Permalink
refact(i18n): adjust locale module after merged time axis.
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Jul 30, 2020
1 parent 4c41f28 commit 4b61d0d
Show file tree
Hide file tree
Showing 28 changed files with 653 additions and 454 deletions.
16 changes: 8 additions & 8 deletions src/component/legend/LegendModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ type LegendDefaultSelectorOptionsProps = {
title: string;
};
const getDefaultSelectorOptions = function (ecModel: GlobalModel, type: string): LegendDefaultSelectorOptionsProps {
if(type === 'all') {
if (type === 'all') {
return {
type: 'all',
title: ecModel.getWithLocale('legend.selector.all')
}
} else if(type === 'inverse') {
title: ecModel.getLocale(['legend', 'selector', 'all'])
};
}
else if (type === 'inverse') {
return {
type: 'inverse',
title: ecModel.getWithLocale('legend.selector.inverse')
}
title: ecModel.getLocale(['legend', 'selector', 'inverse'])
};
}
}

};

type SelectorType = 'all' | 'inverse';
export interface LegendSelectorButtonOption {
Expand Down
1 change: 1 addition & 0 deletions src/component/timeline/SliderTimelineView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ function createScaleByModel(model: SliderTimelineModel, axisType?: string): Scal
});
case 'time':
return new TimeScale({
lang: model.ecModel.getLocaleModel(),
useUTC: model.ecModel.get('useUTC')
});
default:
Expand Down
2 changes: 1 addition & 1 deletion src/component/toolbox/feature/Brush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class BrushFeature extends ToolboxFeature<ToolboxBrushFeatureOption> {
/* eslint-enable */
},
// `rect`, `polygon`, `lineX`, `lineY`, `keep`, `clear`
title: ecModel.getWithLocale('toolbox.brush.title')
title: ecModel.getLocale(['toolbox', 'brush', 'title'])
}

return defaultOption;
Expand Down
7 changes: 3 additions & 4 deletions src/component/toolbox/feature/DataView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import ExtensionAPI from '../../../ExtensionAPI';
import { addEventListener } from 'zrender/src/core/event';
import Axis from '../../../coord/Axis';
import Cartesian2D from '../../../coord/cartesian/Cartesian2D';
import {ToolboxSaveAsImageFeatureOption} from "./SaveAsImage";

const BLOCK_SPLITER = new Array(60).join('-');
const ITEM_SPLITER = '\t';
Expand Down Expand Up @@ -430,15 +429,15 @@ class DataView extends ToolboxFeature<ToolboxDataViewFeatureOption> {

// 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'),
title: ecModel.getLocale(['toolbox', 'dataView', 'title']),
lang: ecModel.getLocale(['toolbox', 'dataView', 'lang']),
backgroundColor: '#fff',
textColor: '#000',
textareaColor: '#fff',
textareaBorderColor: '#333',
buttonColor: '#c23531',
buttonTextColor: '#fff'
}
};

return defaultOption;
}
Expand Down
4 changes: 2 additions & 2 deletions src/component/toolbox/feature/DataZoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ class DataZoomFeature extends ToolboxFeature<ToolboxDataZoomFeatureOption> {
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'),
}
title: ecModel.getLocale(['toolbox', 'dataZoom', 'title'])
};

return defaultOption;
}
Expand Down
10 changes: 5 additions & 5 deletions src/component/toolbox/feature/MagicType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ class MagicType extends ToolboxFeature<ToolboxMagicTypeFeatureOption> {
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.magicType.title'),
title: ecModel.getLocale(['toolbox', 'magicType', 'title']),
option: {},
seriesIndex: {}
}
};

return defaultOption;
}
Expand Down Expand Up @@ -155,12 +155,12 @@ class MagicType extends ToolboxFeature<ToolboxMagicTypeFeatureOption> {
// Change title of stack
if (type === 'stack') {
const seriesOptions = newOption.series as (SeriesOption & { stack: string })[];
const titldLang = ecModel.getWithLocale('toolbox.magicType.title.tiled');
const titleLang = ecModel.getWithLocale('toolbox.magicType.title');
const tiledLang = ecModel.getLocale(['toolbox', 'magicType', 'title', 'tiled'] as any);
const titleLang = ecModel.getLocale(['toolbox', 'magicType', 'title']);
const isStack = seriesOptions && seriesOptions[0]
&& seriesOptions[0].stack === INNER_STACK_KEYWORD;
newTitle = isStack
? zrUtil.merge({ stack: titldLang }, titleLang)
? zrUtil.merge({ stack: tiledLang }, titleLang)
: zrUtil.clone(titleLang);
}

Expand Down
4 changes: 2 additions & 2 deletions src/component/toolbox/feature/Restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class RestoreOption extends ToolboxFeature<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'),
}
title: ecModel.getLocale(['toolbox', 'restore', 'title'])
};

return defaultOption;
}
Expand Down
6 changes: 3 additions & 3 deletions src/component/toolbox/feature/SaveAsImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ class SaveAsImage extends ToolboxFeature<ToolboxSaveAsImageFeatureOption> {
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'),
title: ecModel.getLocale(['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)
}
lang: ecModel.getLocale(['toolbox', 'saveAsImage', 'lang'])
};

return defaultOption;
}
Expand Down
1 change: 1 addition & 0 deletions src/coord/axisHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export function createScaleByModel(model: AxisBaseModel, axisType?: string): Sca
});
case 'time':
return new TimeScale({
locale: model.ecModel.getLocaleModel(),
useUTC: model.ecModel.get('useUTC')
});
default:
Expand Down
38 changes: 6 additions & 32 deletions src/echarts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import {
ActionHandler, ActionInfo, OptionPreprocessor, PostUpdater,
LoadingEffect, LoadingEffectCreator, StageHandlerInternal,
StageHandlerOverallReset, StageHandler,
ViewRootGroup, DimensionDefinitionLoose, ECEventData, ThemeOption, LocaleOption,
ViewRootGroup, DimensionDefinitionLoose, ECEventData, ThemeOption,
ECOption,
ECUnitOption,
ZRColor,
Expand All @@ -97,12 +97,10 @@ 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';
import { createLocaleObject, SYSTEM_LANG, LocaleOption } from './locale';

declare let global: any;
type ModelFinder = modelUtil.ModelFinder;
Expand Down Expand Up @@ -359,27 +357,7 @@ class ECharts extends Eventful {

this._theme = theme;

const defaultLocale = 'EN';
const browserLang: string = !env.domSupported ? defaultLocale : (() => {
const langStr = (document.documentElement.lang || navigator.language || (navigator as any).browserLanguage).toUpperCase();
return langStr.indexOf('ZH') > -1 ? 'ZH' : defaultLocale;
})();
const {locale = browserLang} = opts;
// set default lang package
localeStorage['ZH'] = localeStorage['ZH'] || langZH;
localeStorage['EN'] = localeStorage['EN'] || langEN;
this._locale = ((locale) => {
if (zrUtil.isString(locale)) {
const localeObj = localeStorage[locale.toUpperCase()] || {};
if (locale === 'ZH' || locale === 'EN') {
return zrUtil.clone(localeObj);
} else {
return zrUtil.merge(zrUtil.clone(localeObj), zrUtil.clone(localeStorage[defaultLocale]), false);
}
} else {
return zrUtil.merge(zrUtil.clone(locale), zrUtil.clone(localeStorage[defaultLocale]), false);
}
})(locale);
this._locale = createLocaleObject(opts.locale || SYSTEM_LANG);

this._coordSysMgr = new CoordinateSystemManager();

Expand Down Expand Up @@ -2353,8 +2331,6 @@ const visualFuncs: StageHandlerInternal[] = [];

const themeStorage: {[themeName: string]: ThemeOption} = {};

const localeStorage: {[localeName: string]: LocaleOption} = {};

const loadingEffects: {[effectName: string]: LoadingEffectCreator} = {};

const instances: {[id: string]: ECharts} = {};
Expand All @@ -2381,7 +2357,7 @@ export function init(
devicePixelRatio?: number,
width?: number,
height?: number,
locale?: string | object
locale?: string | LocaleOption
}
): ECharts {
if (__DEV__) {
Expand Down Expand Up @@ -2514,10 +2490,6 @@ export function registerTheme(name: string, theme: ThemeOption): void {
themeStorage[name] = theme;
}

export function registerLocale(name: string, locale: LocaleOption): void {
localeStorage[name] = locale;
}

/**
* Register option preprocessor
*/
Expand Down Expand Up @@ -2610,6 +2582,8 @@ export function getCoordinateSystemDimensions(type: string): DimensionDefinition
}
}

export {registerLocale} from './locale';

/**
* Layout is a special stage of visual encoding
* Most visual encoding like color are common for different chart
Expand Down
109 changes: 0 additions & 109 deletions src/i18n/langEN.json

This file was deleted.

Loading

0 comments on commit 4b61d0d

Please sign in to comment.